Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: small modification to NgHeader #33289

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/node_http_common-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ size_t GetServerMaxHeaderPairs(size_t max_header_pairs) {
return std::max(max_header_pairs, min_header_pairs);
}

template <typename allocator_t>
std::string NgHeaderImpl<allocator_t>::ToString() const {
std::string ret = name();
ret += " = ";
ret += value();
return ret;
}

template <typename T>
bool NgHeader<T>::IsZeroLength(
NgHeader<T>::rcbuf_t* name,
Expand Down Expand Up @@ -132,6 +140,12 @@ NgHeader<T>::NgHeader(NgHeader<T>&& other) noexcept
other.env_ = nullptr;
}

template <typename T>
void NgHeader<T>::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackField("name", name_);
tracker->TrackField("value", value_);
}

template <typename T>
v8::MaybeLocal<v8::String> NgHeader<T>::GetName(
NgHeader<T>::allocator_t* allocator) const {
Expand Down
36 changes: 19 additions & 17 deletions src/node_http_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ class NgRcBufPointer : public MemoryRetainer {
bool internalizable_ = false;
};

template <typename allocator_t>
struct NgHeaderImpl : public MemoryRetainer {
jasnell marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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 : public NgHeaderImpl<typename T::allocator_t> {
jasnell marked this conversation as resolved.
Show resolved Hide resolved
public:
typedef typename T::rcbufferpointer_t rcbufferpointer_t;
typedef typename T::rcbufferpointer_t::rcbuf_t rcbuf_t;
Expand All @@ -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_;
Expand Down