Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 5500d55

Browse files
committed
quic: get name and value as std::string option
PR-URL: #217 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 700ab33 commit 5500d55

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/node_quic_http3_application.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <nghttp3/nghttp3.h>
1212
#include <algorithm>
13+
#include <string>
1314

1415
namespace node {
1516

@@ -59,6 +60,13 @@ Http3Header::Http3Header(
5960
value_.reset(value);
6061
}
6162

63+
Http3Header::Http3Header(Http3Header&& other) noexcept :
64+
token_(other.token_),
65+
name_(std::move(other.name_)),
66+
value_(std::move(other.value_)) {
67+
other.token_ = -1;
68+
}
69+
6270
MaybeLocal<String> Http3Header::GetName(QuicApplication* app) const {
6371
const char* header_name = to_http_header_name(token_);
6472
Environment* env = app->env();
@@ -97,6 +105,28 @@ MaybeLocal<String> Http3Header::GetValue(QuicApplication* app) const {
97105
value_);
98106
}
99107

108+
std::string Http3Header::GetName() const {
109+
const char* header_name = to_http_header_name(token_);
110+
if (header_name != nullptr)
111+
return std::string(header_name);
112+
113+
if (UNLIKELY(!name_))
114+
return std::string(); // Empty String
115+
116+
return std::string(
117+
reinterpret_cast<const char*>(name_.data()),
118+
name_.len());
119+
}
120+
121+
std::string Http3Header::GetValue() const {
122+
if (UNLIKELY(!value_))
123+
return std::string(); // Empty String
124+
125+
return std::string(
126+
reinterpret_cast<const char*>(value_.data()),
127+
value_.len());
128+
}
129+
100130
namespace {
101131
template <typename t>
102132
inline void SetConfig(Environment* env, int idx, t* val) {

src/node_quic_http3_application.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <ngtcp2/ngtcp2.h>
1414
#include <nghttp3/nghttp3.h>
1515

16+
#include <string>
1617
namespace node {
1718

1819
namespace quic {
@@ -52,16 +53,14 @@ using Http3ConnectionPointer = DeleteFnPtr<nghttp3_conn, nghttp3_conn_del>;
5253
class Http3Header : public QuicHeader {
5354
public:
5455
Http3Header(int32_t token, nghttp3_rcbuf* name, nghttp3_rcbuf* value);
55-
Http3Header(Http3Header&& other) noexcept :
56-
token_(other.token_),
57-
name_(std::move(other.name_)),
58-
value_(std::move(other.value_)) {
59-
other.token_ = -1;
60-
}
56+
Http3Header(Http3Header&& other) noexcept;
6157

6258
v8::MaybeLocal<v8::String> GetName(QuicApplication* app) const override;
6359
v8::MaybeLocal<v8::String> GetValue(QuicApplication* app) const override;
6460

61+
std::string GetName() const override;
62+
std::string GetValue() const override;
63+
6564
private:
6665
int32_t token_ = -1;
6766
Http3RcBufferPointer name_;

src/node_quic_stream.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "stream_base-inl.h"
1212
#include "v8.h"
1313

14+
#include <string>
1415
#include <vector>
1516

1617
namespace node {
@@ -60,6 +61,8 @@ class QuicHeader {
6061
virtual ~QuicHeader() {}
6162
virtual v8::MaybeLocal<v8::String> GetName(QuicApplication* app) const = 0;
6263
virtual v8::MaybeLocal<v8::String> GetValue(QuicApplication* app) const = 0;
64+
virtual std::string GetName() const = 0;
65+
virtual std::string GetValue() const = 0;
6366
};
6467

6568
// QuicStream's are simple data flows that, fortunately, do not

0 commit comments

Comments
 (0)