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

Commit

Permalink
quic: get name and value as std::string option
Browse files Browse the repository at this point in the history
PR-URL: #217
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
jasnell committed Dec 5, 2019
1 parent 700ab33 commit 5500d55
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/node_quic_http3_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <nghttp3/nghttp3.h>
#include <algorithm>
#include <string>

namespace node {

Expand Down Expand Up @@ -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<String> Http3Header::GetName(QuicApplication* app) const {
const char* header_name = to_http_header_name(token_);
Environment* env = app->env();
Expand Down Expand Up @@ -97,6 +105,28 @@ MaybeLocal<String> 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<const char*>(name_.data()),
name_.len());
}

std::string Http3Header::GetValue() const {
if (UNLIKELY(!value_))
return std::string(); // Empty String

return std::string(
reinterpret_cast<const char*>(value_.data()),
value_.len());
}

namespace {
template <typename t>
inline void SetConfig(Environment* env, int idx, t* val) {
Expand Down
11 changes: 5 additions & 6 deletions src/node_quic_http3_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ngtcp2/ngtcp2.h>
#include <nghttp3/nghttp3.h>

#include <string>
namespace node {

namespace quic {
Expand Down Expand Up @@ -52,16 +53,14 @@ using Http3ConnectionPointer = DeleteFnPtr<nghttp3_conn, nghttp3_conn_del>;
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<v8::String> GetName(QuicApplication* app) const override;
v8::MaybeLocal<v8::String> GetValue(QuicApplication* app) const override;

std::string GetName() const override;
std::string GetValue() const override;

private:
int32_t token_ = -1;
Http3RcBufferPointer name_;
Expand Down
3 changes: 3 additions & 0 deletions src/node_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "stream_base-inl.h"
#include "v8.h"

#include <string>
#include <vector>

namespace node {
Expand Down Expand Up @@ -60,6 +61,8 @@ class QuicHeader {
virtual ~QuicHeader() {}
virtual v8::MaybeLocal<v8::String> GetName(QuicApplication* app) const = 0;
virtual v8::MaybeLocal<v8::String> 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
Expand Down

0 comments on commit 5500d55

Please sign in to comment.