Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2020-05-07 22:49:05 +0300
committerJames M Snell <jasnell@gmail.com>2020-05-14 18:56:41 +0300
commit241ed44a0b06db45c97681c164fc1098e7c9f0d2 (patch)
treedc8c790352d9bc3d6fe35cb69d9bb32aeefc556e /src/node_http_common.h
parent1dafaf03cb35d51562193afab6e903a10a89d906 (diff)
src: small modification to NgHeader
This is separated out of the QUIC PR. It is not specific to QUIC but provides a new base class that is used there as an abstraction of the actual implementation. This is a purely internal implementation detail that has no outward functional changes (so no need for tests) Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/33289 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/node_http_common.h')
-rw-r--r--src/node_http_common.h36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/node_http_common.h b/src/node_http_common.h
index d2bdddd93f4..c7e4d34af24 100644
--- a/src/node_http_common.h
+++ b/src/node_http_common.h
@@ -453,6 +453,16 @@ class NgRcBufPointer : public MemoryRetainer {
bool internalizable_ = false;
};
+template <typename allocator_t>
+struct NgHeaderBase : public MemoryRetainer {
+ virtual v8::MaybeLocal<v8::String> GetName(allocator_t* allocator) const = 0;
+ virtual v8::MaybeLocal<v8::String> GetValue(allocator_t* allocator) const = 0;
+ virtual std::string name() const = 0;
+ virtual std::string value() const = 0;
+ virtual size_t length() const = 0;
+ virtual std::string ToString() const;
+};
+
// The ng libraries use nearly identical structs to represent
// received http headers. The NgHeader class wraps those in a
// consistent way and allows converting the name and value to
@@ -461,7 +471,7 @@ class NgRcBufPointer : public MemoryRetainer {
// memory tracking, and implementation of static utility functions.
// See Http2HeaderTraits in node_http2.h for an example.
template <typename T>
-class NgHeader : public MemoryRetainer {
+class NgHeader final : public NgHeaderBase<typename T::allocator_t> {
public:
typedef typename T::rcbufferpointer_t rcbufferpointer_t;
typedef typename T::rcbufferpointer_t::rcbuf_t rcbuf_t;
@@ -487,28 +497,20 @@ class NgHeader : public MemoryRetainer {
// object to the v8 string. Once the v8 string is garbage collected,
// the reference counter will be decremented.
- inline v8::MaybeLocal<v8::String> GetName(allocator_t* allocator) const;
- inline v8::MaybeLocal<v8::String> GetValue(allocator_t* allocator) const;
+ inline v8::MaybeLocal<v8::String> GetName(
+ allocator_t* allocator) const override;
+ inline v8::MaybeLocal<v8::String> GetValue(
+ allocator_t* allocator) const override;
- inline std::string name() const;
- inline std::string value() const;
- inline size_t length() const;
+ inline std::string name() const override;
+ inline std::string value() const override;
+ inline size_t length() const override;
- void MemoryInfo(MemoryTracker* tracker) const override {
- tracker->TrackField("name", name_);
- tracker->TrackField("value", value_);
- }
+ void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(NgHeader)
SET_SELF_SIZE(NgHeader)
- std::string ToString() const {
- std::string ret = name();
- ret += " = ";
- ret += value();
- return ret;
- }
-
private:
Environment* env_;
rcbufferpointer_t name_;