diff --git a/src/node_quic_http3_application.cc b/src/node_quic_http3_application.cc index 01aa699389..176c1cac65 100644 --- a/src/node_quic_http3_application.cc +++ b/src/node_quic_http3_application.cc @@ -10,6 +10,7 @@ #include #include +#include namespace node { @@ -59,6 +60,13 @@ Http3Header::Http3Header( value_.reset(value); } +Http3Header::Http3Header(Http3Header&& other) noexcept : + token_(other.token_), + name_(std::move(other.name_)), + value_(std::move(other.value_)) { + other.token_ = -1; +} + MaybeLocal Http3Header::GetName(QuicApplication* app) const { const char* header_name = to_http_header_name(token_); Environment* env = app->env(); @@ -97,6 +105,28 @@ MaybeLocal Http3Header::GetValue(QuicApplication* app) const { value_); } +std::string Http3Header::GetName() const { + const char* header_name = to_http_header_name(token_); + if (header_name != nullptr) + return std::string(header_name); + + if (UNLIKELY(!name_)) + return std::string(); // Empty String + + return std::string( + reinterpret_cast(name_.data()), + name_.len()); +} + +std::string Http3Header::GetValue() const { + if (UNLIKELY(!value_)) + return std::string(); // Empty String + + return std::string( + reinterpret_cast(value_.data()), + value_.len()); +} + namespace { template inline void SetConfig(Environment* env, int idx, t* val) { diff --git a/src/node_quic_http3_application.h b/src/node_quic_http3_application.h index 5c234cd8b4..cd54d7b755 100644 --- a/src/node_quic_http3_application.h +++ b/src/node_quic_http3_application.h @@ -13,6 +13,7 @@ #include #include +#include namespace node { namespace quic { @@ -52,16 +53,14 @@ using Http3ConnectionPointer = DeleteFnPtr; class Http3Header : public QuicHeader { public: Http3Header(int32_t token, nghttp3_rcbuf* name, nghttp3_rcbuf* value); - Http3Header(Http3Header&& other) noexcept : - token_(other.token_), - name_(std::move(other.name_)), - value_(std::move(other.value_)) { - other.token_ = -1; - } + Http3Header(Http3Header&& other) noexcept; v8::MaybeLocal GetName(QuicApplication* app) const override; v8::MaybeLocal GetValue(QuicApplication* app) const override; + std::string GetName() const override; + std::string GetValue() const override; + private: int32_t token_ = -1; Http3RcBufferPointer name_; diff --git a/src/node_quic_stream.h b/src/node_quic_stream.h index 23205c2948..bd522e2643 100644 --- a/src/node_quic_stream.h +++ b/src/node_quic_stream.h @@ -11,6 +11,7 @@ #include "stream_base-inl.h" #include "v8.h" +#include #include namespace node { @@ -60,6 +61,8 @@ class QuicHeader { virtual ~QuicHeader() {} virtual v8::MaybeLocal GetName(QuicApplication* app) const = 0; virtual v8::MaybeLocal GetValue(QuicApplication* app) const = 0; + virtual std::string GetName() const = 0; + virtual std::string GetValue() const = 0; }; // QuicStream's are simple data flows that, fortunately, do not