Add flags to nghttp2_nv structure

This is preliminary change for upcoming HPACK updates.  The flags are
used to determine the name/value pair is indexable or not.
This commit is contained in:
Tatsuhiro Tsujikawa 2014-04-01 23:17:50 +09:00
parent da5db205ca
commit 24cb90806d
10 changed files with 56 additions and 12 deletions

View File

@ -53,11 +53,13 @@ enum {
#define MAKE_NV(NAME, VALUE) \ #define MAKE_NV(NAME, VALUE) \
{(uint8_t*)NAME, (uint8_t*)VALUE, \ {(uint8_t*)NAME, (uint8_t*)VALUE, \
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(sizeof(VALUE) - 1) } (uint16_t)(sizeof(NAME) - 1), (uint16_t)(sizeof(VALUE) - 1), \
NGHTTP2_NV_FLAG_NONE }
#define MAKE_NV_CS(NAME, VALUE) \ #define MAKE_NV_CS(NAME, VALUE) \
{(uint8_t*)NAME, (uint8_t*)VALUE, \ {(uint8_t*)NAME, (uint8_t*)VALUE, \
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(strlen(VALUE)) } (uint16_t)(sizeof(NAME) - 1), (uint16_t)(strlen(VALUE)), \
NGHTTP2_NV_FLAG_NONE }
struct Connection { struct Connection {
SSL *ssl; SSL *ssl;

View File

@ -381,10 +381,12 @@ static void send_client_connection_header(http2_session_data *session_data)
} }
#define MAKE_NV(NAME, VALUE, VALUELEN) \ #define MAKE_NV(NAME, VALUE, VALUELEN) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, VALUELEN } { (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, VALUELEN, \
NGHTTP2_NV_FLAG_NONE }
#define MAKE_NV2(NAME, VALUE) \ #define MAKE_NV2(NAME, VALUE) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1 } { (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1, \
NGHTTP2_NV_FLAG_NONE }
/* Send HTTP request to the remote peer */ /* Send HTTP request to the remote peer */
static void submit_request(http2_session_data *session_data) static void submit_request(http2_session_data *session_data)

View File

@ -49,7 +49,8 @@
#define ARRLEN(x) (sizeof(x)/sizeof(x[0])) #define ARRLEN(x) (sizeof(x)/sizeof(x[0]))
#define MAKE_NV(NAME, VALUE) \ #define MAKE_NV(NAME, VALUE) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1 } { (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1, \
NGHTTP2_NV_FLAG_NONE }
struct app_context; struct app_context;
typedef struct app_context app_context; typedef struct app_context app_context;

View File

@ -346,6 +346,22 @@ typedef enum {
NGHTTP2_MSG_MORE NGHTTP2_MSG_MORE
} nghttp2_io_flag; } nghttp2_io_flag;
/**
* @enum
*
* The flags for header field name/value pair.
*/
typedef enum {
/**
* No flag set.
*/
NGHTTP2_NV_FLAG_NONE = 0,
/**
* Indicates that this name/value pair must not be indexed.
*/
NGHTTP2_NV_FLAG_NO_INDEX = 0x1
} nghttp2_nv_flag;
/** /**
* @struct * @struct
* *
@ -370,6 +386,10 @@ typedef struct {
* The length of the |value|. * The length of the |value|.
*/ */
uint16_t valuelen; uint16_t valuelen;
/**
* Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
*/
uint8_t flags;
} nghttp2_nv; } nghttp2_nv;
/** /**

View File

@ -919,6 +919,8 @@ ssize_t nghttp2_nv_array_copy(nghttp2_nv **nva_ptr,
data = (uint8_t*)(*nva_ptr) + sizeof(nghttp2_nv)*nvlen; data = (uint8_t*)(*nva_ptr) + sizeof(nghttp2_nv)*nvlen;
for(i = 0; i < nvlen; ++i) { for(i = 0; i < nvlen; ++i) {
p->flags = nva[i].flags;
memcpy(data, nva[i].name, nva[i].namelen); memcpy(data, nva[i].name, nva[i].namelen);
p->name = data; p->name = data;
p->namelen = nva[i].namelen; p->namelen = nva[i].namelen;

View File

@ -34,7 +34,7 @@
/* Make scalar initialization form of nghttp2_nv */ /* Make scalar initialization form of nghttp2_nv */
#define MAKE_STATIC_ENT(I, N, V, NH, VH) \ #define MAKE_STATIC_ENT(I, N, V, NH, VH) \
{ { { (uint8_t*)N, (uint8_t*)V, sizeof(N) - 1, sizeof(V) - 1 }, \ { { { (uint8_t*)N, (uint8_t*)V, sizeof(N) - 1, sizeof(V) - 1, 0 }, \
NH, VH, 1, NGHTTP2_HD_FLAG_NONE }, I } NH, VH, 1, NGHTTP2_HD_FLAG_NONE }, I }
/* Sorted by hash(name) and its table index */ /* Sorted by hash(name) and its table index */
@ -144,6 +144,11 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags,
uint8_t *value, uint16_t valuelen) uint8_t *value, uint16_t valuelen)
{ {
int rv = 0; int rv = 0;
/* Since nghttp2_hd_entry is used for indexing, ent->nv.flags always
NGHTTP2_NV_FLAG_NONE */
ent->nv.flags = NGHTTP2_NV_FLAG_NONE;
if((flags & NGHTTP2_HD_FLAG_NAME_ALLOC) && if((flags & NGHTTP2_HD_FLAG_NAME_ALLOC) &&
(flags & NGHTTP2_HD_FLAG_NAME_GIFT) == 0) { (flags & NGHTTP2_HD_FLAG_NAME_GIFT) == 0) {
if(namelen == 0) { if(namelen == 0) {
@ -1402,6 +1407,9 @@ static int hd_inflate_commit_newname(nghttp2_hd_inflater *inflater,
return NGHTTP2_ERR_NOMEM; return NGHTTP2_ERR_NOMEM;
} }
/* Set NGHTTP2_NV_FLAG_NO_INDEX if never indexing repr is used */
nv.flags = NGHTTP2_NV_FLAG_NONE;
if(inflater->index_required) { if(inflater->index_required) {
nghttp2_hd_entry *new_ent; nghttp2_hd_entry *new_ent;
uint8_t ent_flags; uint8_t ent_flags;
@ -1455,6 +1463,9 @@ static int hd_inflate_commit_indname(nghttp2_hd_inflater *inflater,
return NGHTTP2_ERR_NOMEM; return NGHTTP2_ERR_NOMEM;
} }
/* Set NGHTTP2_NV_FLAG_NO_INDEX if never indexing repr is used */
nv.flags = NGHTTP2_NV_FLAG_NONE;
nv.name = inflater->ent_name->nv.name; nv.name = inflater->ent_name->nv.name;
nv.namelen = inflater->ent_name->nv.namelen; nv.namelen = inflater->ent_name->nv.namelen;

View File

@ -341,7 +341,8 @@ nghttp2_nv make_nv(const std::string& name, const std::string& value)
return { return {
(uint8_t*)name.c_str(), (uint8_t*)name.c_str(),
(uint8_t*)value.c_str(), (uint8_t*)value.c_str(),
(uint16_t)name.size(), (uint16_t)value.size() (uint16_t)name.size(), (uint16_t)value.size(),
NGHTTP2_NV_FLAG_NONE
}; };
} }

View File

@ -130,7 +130,8 @@ template<size_t N, size_t M>
nghttp2_nv make_nv_ll(const char(&name)[N], const char(&value)[M]) nghttp2_nv make_nv_ll(const char(&name)[N], const char(&value)[M])
{ {
return { (uint8_t*)name, (uint8_t*)value, return { (uint8_t*)name, (uint8_t*)value,
(uint16_t)(N - 1), (uint16_t)(M - 1) }; (uint16_t)(N - 1), (uint16_t)(M - 1),
NGHTTP2_NV_FLAG_NONE };
} }
// Create nghttp2_nv from string literal |name| and c-string |value|. // Create nghttp2_nv from string literal |name| and c-string |value|.
@ -138,7 +139,8 @@ template<size_t N>
nghttp2_nv make_nv_lc(const char(&name)[N], const char *value) nghttp2_nv make_nv_lc(const char(&name)[N], const char *value)
{ {
return { (uint8_t*)name, (uint8_t*)value, return { (uint8_t*)name, (uint8_t*)value,
(uint16_t)(N - 1), (uint16_t)strlen(value) }; (uint16_t)(N - 1), (uint16_t)strlen(value),
NGHTTP2_NV_FLAG_NONE };
} }
// Create nghttp2_nv from string literal |name| and std::string // Create nghttp2_nv from string literal |name| and std::string
@ -147,7 +149,8 @@ template<size_t N>
nghttp2_nv make_nv_ls(const char(&name)[N], const std::string& value) nghttp2_nv make_nv_ls(const char(&name)[N], const std::string& value)
{ {
return { (uint8_t*)name, (uint8_t*)value.c_str(), return { (uint8_t*)name, (uint8_t*)value.c_str(),
(uint16_t)(N - 1), (uint16_t)value.size() }; (uint16_t)(N - 1), (uint16_t)value.size(),
NGHTTP2_NV_FLAG_NONE };
} }
// Appends headers in |headers| to |nv|. Certain headers, including // Appends headers in |headers| to |nv|. Certain headers, including

View File

@ -38,7 +38,8 @@
using namespace nghttp2; using namespace nghttp2;
#define MAKE_NV(K, V) {(uint8_t*)K, (uint8_t*)V, \ #define MAKE_NV(K, V) {(uint8_t*)K, (uint8_t*)V, \
(uint16_t)(sizeof(K)-1), (uint16_t)(sizeof(V)-1)} (uint16_t)(sizeof(K)-1), (uint16_t)(sizeof(V)-1), \
NGHTTP2_NV_FLAG_NONE }
namespace shrpx { namespace shrpx {

View File

@ -34,7 +34,8 @@
#include "nghttp2_session.h" #include "nghttp2_session.h"
#define MAKE_NV(NAME, VALUE) \ #define MAKE_NV(NAME, VALUE) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, strlen(NAME), strlen(VALUE) } { (uint8_t*)NAME, (uint8_t*)VALUE, strlen(NAME), strlen(VALUE), \
NGHTTP2_NV_FLAG_NONE }
#define ARRLEN(ARR) (sizeof(ARR)/sizeof(ARR[0])) #define ARRLEN(ARR) (sizeof(ARR)/sizeof(ARR[0]))
#define assert_nv_equal(A, B, len) \ #define assert_nv_equal(A, B, len) \