Remove nghttp2_submit_* API functions which has char **nv parameter
The nghttp2_submit_{request,response}2 functions are renamed as nghttp2_submit_{request, response}.
This commit is contained in:
parent
d6212a6055
commit
6c77cec270
|
@ -51,6 +51,14 @@ enum {
|
||||||
WANT_WRITE
|
WANT_WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MAKE_NV(NAME, VALUE) \
|
||||||
|
{(uint8_t*)NAME, (uint8_t*)VALUE, \
|
||||||
|
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(sizeof(VALUE) - 1) }
|
||||||
|
|
||||||
|
#define MAKE_NV_CS(NAME, VALUE) \
|
||||||
|
{(uint8_t*)NAME, (uint8_t*)VALUE, \
|
||||||
|
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(strlen(VALUE)) }
|
||||||
|
|
||||||
struct Connection {
|
struct Connection {
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
nghttp2_session *session;
|
nghttp2_session *session;
|
||||||
|
@ -515,16 +523,17 @@ static void submit_request(struct Connection *connection, struct Request *req)
|
||||||
{
|
{
|
||||||
int pri = 0;
|
int pri = 0;
|
||||||
int rv;
|
int rv;
|
||||||
const char *nv[13];
|
const nghttp2_nv nva[] = {
|
||||||
/* Make sure that the last item is NULL */
|
/* Make sure that the last item is NULL */
|
||||||
nv[0] = ":method"; nv[1] = "GET";
|
MAKE_NV(":method", "GET"),
|
||||||
nv[2] = ":path"; nv[3] = req->path;
|
MAKE_NV_CS(":path", req->path),
|
||||||
nv[4] = ":scheme"; nv[5] = "https";
|
MAKE_NV(":scheme", "https"),
|
||||||
nv[6] = ":host"; nv[7] = req->hostport;
|
MAKE_NV_CS(":host", req->hostport),
|
||||||
nv[8] = "accept"; nv[9] = "*/*";
|
MAKE_NV("accept", "*/*"),
|
||||||
nv[10] = "user-agent"; nv[11] = "nghttp2/"NGHTTP2_VERSION;
|
MAKE_NV("user-agent", "nghttp2/"NGHTTP2_VERSION)
|
||||||
nv[12] = NULL;
|
};
|
||||||
rv = nghttp2_submit_request(connection->session, pri, nv, NULL, req);
|
rv = nghttp2_submit_request(connection->session, pri,
|
||||||
|
nva, sizeof(nva)/sizeof(nva[0]), NULL, req);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
diec("nghttp2_submit_request", rv);
|
diec("nghttp2_submit_request", rv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1764,27 +1764,20 @@ const char* nghttp2_strerror(int lib_error_code);
|
||||||
* The |pri| is priority of this request. 0 is the highest priority
|
* The |pri| is priority of this request. 0 is the highest priority
|
||||||
* value and :macro:`NGHTTP2_PRI_LOWEST` is the lowest value.
|
* value and :macro:`NGHTTP2_PRI_LOWEST` is the lowest value.
|
||||||
*
|
*
|
||||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
* |nvlen| elements.
|
||||||
* pointer to the value string. The one beyond last value must be
|
|
||||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
|
||||||
* ``nv[2*N]`` must be ``NULL``.
|
|
||||||
*
|
*
|
||||||
* HTTP/2.0 specification has requirement about header fields in the
|
* HTTP/2.0 specification has requirement about header fields in the
|
||||||
* request HEADERS. See the specification for more details.
|
* request HEADERS. See the specification for more details.
|
||||||
*
|
*
|
||||||
* This function creates copies of all name/value pairs in |nv|. It
|
* This function creates copies of all name/value pairs in |nva|. It
|
||||||
* also lower-cases all names in |nv|.
|
* also lower-cases all names in |nva|.
|
||||||
*
|
|
||||||
* The string in |nv| must be NULL-terminated. Use
|
|
||||||
* `nghttp2_submit_request2()` if name/value pairs are not
|
|
||||||
* NULL-terminated strings.
|
|
||||||
*
|
*
|
||||||
* If |data_prd| is not ``NULL``, it provides data which will be sent
|
* If |data_prd| is not ``NULL``, it provides data which will be sent
|
||||||
* in subsequent DATA frames. In this case, a method that allows
|
* in subsequent DATA frames. In this case, a method that allows
|
||||||
* request message bodies
|
* request message bodies
|
||||||
* (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9) must
|
* (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9) must
|
||||||
* be specified with ``:method`` key in |nv| (e.g. ``POST``). This
|
* be specified with ``:method`` key in |nva| (e.g. ``POST``). This
|
||||||
* function does not take ownership of the |data_prd|. The function
|
* function does not take ownership of the |data_prd|. The function
|
||||||
* copies the members of the |data_prd|. If |data_prd| is ``NULL``,
|
* copies the members of the |data_prd|. If |data_prd| is ``NULL``,
|
||||||
* HEADERS have END_STREAM set. The |stream_user_data| is data
|
* HEADERS have END_STREAM set. The |stream_user_data| is data
|
||||||
|
@ -1808,55 +1801,30 @@ const char* nghttp2_strerror(int lib_error_code);
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||||
* The |pri| is invalid; or the |nv| includes empty name or
|
* The |pri| is invalid; or the |nva| includes empty name, or name
|
||||||
* ``NULL`` value.
|
* which contains invalid characters.
|
||||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_submit_request(nghttp2_session *session, int32_t pri,
|
int nghttp2_submit_request(nghttp2_session *session, int32_t pri,
|
||||||
const char **nv,
|
const nghttp2_nv *nva, size_t nvlen,
|
||||||
const nghttp2_data_provider *data_prd,
|
const nghttp2_data_provider *data_prd,
|
||||||
void *stream_user_data);
|
void *stream_user_data);
|
||||||
|
|
||||||
/**
|
|
||||||
* @function
|
|
||||||
*
|
|
||||||
* Just like `nghttp2_submit_request()`, but this function takes the
|
|
||||||
* |nva|, which is an array of ``nghttp2_nv`` with |nvlen| elements,
|
|
||||||
* as name/value pairs. This function is useful if name/value pairs
|
|
||||||
* are not NULL-terminated strings.
|
|
||||||
*
|
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
|
||||||
* negative error codes:
|
|
||||||
*
|
|
||||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
|
||||||
* The |pri| is invalid; or the |nva| includes empty name or
|
|
||||||
* name which contains invalid characters.
|
|
||||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
|
||||||
* Out of memory.
|
|
||||||
*/
|
|
||||||
int nghttp2_submit_request2(nghttp2_session *session, int32_t pri,
|
|
||||||
const nghttp2_nv *nva, size_t nvlen,
|
|
||||||
const nghttp2_data_provider *data_prd,
|
|
||||||
void *stream_user_data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
*
|
*
|
||||||
* Submits response HEADERS frame and optionally one or more DATA
|
* Submits response HEADERS frame and optionally one or more DATA
|
||||||
* frames against the stream |stream_id|.
|
* frames against the stream |stream_id|.
|
||||||
*
|
*
|
||||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
* |nvlen| elements.
|
||||||
* pointer to the value string. The one beyond last value must be
|
|
||||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
|
||||||
* ``nv[2*N]`` must be ``NULL``.
|
|
||||||
*
|
*
|
||||||
* HTTP/2.0 specification has requirement about header fields in the
|
* HTTP/2.0 specification has requirement about header fields in the
|
||||||
* response HEADERS. See the specification for more details.
|
* response HEADERS. See the specification for more details.
|
||||||
*
|
*
|
||||||
* This function creates copies of all name/value pairs in |nv|. It
|
* This function creates copies of all name/value pairs in |nva|. It
|
||||||
* also lower-cases all names in |nv|.
|
* also lower-cases all names in |nva|.
|
||||||
*
|
*
|
||||||
* If |data_prd| is not ``NULL``, it provides data which will be sent
|
* If |data_prd| is not ``NULL``, it provides data which will be sent
|
||||||
* in subsequent DATA frames. This function does not take ownership
|
* in subsequent DATA frames. This function does not take ownership
|
||||||
|
@ -1868,36 +1836,16 @@ int nghttp2_submit_request2(nghttp2_session *session, int32_t pri,
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||||
* The |nv| includes empty name or ``NULL`` value.
|
* The |nva| includes empty name or name which contains invalid
|
||||||
|
* characters.
|
||||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_submit_response(nghttp2_session *session,
|
int nghttp2_submit_response(nghttp2_session *session,
|
||||||
int32_t stream_id, const char **nv,
|
int32_t stream_id,
|
||||||
|
const nghttp2_nv *nva, size_t nvlen,
|
||||||
const nghttp2_data_provider *data_prd);
|
const nghttp2_data_provider *data_prd);
|
||||||
|
|
||||||
/**
|
|
||||||
* @function
|
|
||||||
*
|
|
||||||
* Just like `nghttp2_submit_response()`, but this function takes the
|
|
||||||
* |nva|, which is an array of ``nghttp2_nv`` with |nvlen| elements,
|
|
||||||
* as name/value pairs. This function is useful if name/value pairs
|
|
||||||
* are not NULL-terminated strings.
|
|
||||||
*
|
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
|
||||||
* negative error codes:
|
|
||||||
*
|
|
||||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
|
||||||
* The |pri| is invalid; or the |nva| includes empty name or
|
|
||||||
* name which contains invalid characters.
|
|
||||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
|
||||||
* Out of memory.
|
|
||||||
*/
|
|
||||||
int nghttp2_submit_response2(nghttp2_session *session,
|
|
||||||
int32_t stream_id,
|
|
||||||
const nghttp2_nv *nva, size_t nvlen,
|
|
||||||
const nghttp2_data_provider *data_prd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
*
|
*
|
||||||
|
@ -1921,14 +1869,11 @@ int nghttp2_submit_response2(nghttp2_session *session,
|
||||||
*
|
*
|
||||||
* The |pri| is priority of this request.
|
* The |pri| is priority of this request.
|
||||||
*
|
*
|
||||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
* |nvlen| elements.
|
||||||
* pointer to the value string. The one beyond last value must be
|
|
||||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
|
||||||
* ``nv[2*N]`` must be ``NULL``.
|
|
||||||
*
|
*
|
||||||
* This function creates copies of all name/value pairs in |nv|. It
|
* This function creates copies of all name/value pairs in |nva|. It
|
||||||
* also lower-cases all names in |nv|.
|
* also lower-cases all names in |nva|.
|
||||||
*
|
*
|
||||||
* The |stream_user_data| is a pointer to an arbitrary data which is
|
* The |stream_user_data| is a pointer to an arbitrary data which is
|
||||||
* associated to the stream this frame will open. Therefore it is only
|
* associated to the stream this frame will open. Therefore it is only
|
||||||
|
@ -1943,13 +1888,14 @@ int nghttp2_submit_response2(nghttp2_session *session,
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||||
* The |pri| is invalid; or the |nv| includes empty name or
|
* The |pri| is invalid; or the |nva| includes empty name, or name
|
||||||
* ``NULL`` value.
|
* which contains invalid characters.
|
||||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
||||||
int32_t stream_id, int32_t pri, const char **nv,
|
int32_t stream_id, int32_t pri,
|
||||||
|
const nghttp2_nv *nva, size_t nvlen,
|
||||||
void *stream_user_data);
|
void *stream_user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2059,14 +2005,11 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||||
*
|
*
|
||||||
* The |stream_id| must be client initiated stream ID.
|
* The |stream_id| must be client initiated stream ID.
|
||||||
*
|
*
|
||||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
* |nvlen| elements.
|
||||||
* pointer to the value string. The one beyond last value must be
|
|
||||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
|
||||||
* ``nv[2*N]`` must be ``NULL``.
|
|
||||||
*
|
*
|
||||||
* This function creates copies of all name/value pairs in |nv|. It
|
* This function creates copies of all name/value pairs in |nva|. It
|
||||||
* also lower-cases all names in |nv|.
|
* also lower-cases all names in |nva|.
|
||||||
*
|
*
|
||||||
* Since the library reorders the frames and tries to send the highest
|
* Since the library reorders the frames and tries to send the highest
|
||||||
* prioritized one first and the HTTP/2.0 specification requires the
|
* prioritized one first and the HTTP/2.0 specification requires the
|
||||||
|
@ -2081,14 +2024,16 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||||
* The |nv| includes empty name or ``NULL`` value.
|
* The |nva| includes empty name, or name which contains invalid
|
||||||
|
* characters.
|
||||||
* :enum:`NGHTTP2_ERR_STREAM_CLOSED`
|
* :enum:`NGHTTP2_ERR_STREAM_CLOSED`
|
||||||
* The stream is already closed or does not exist.
|
* The stream is already closed or does not exist.
|
||||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
||||||
int32_t stream_id, const char **nv);
|
int32_t stream_id,
|
||||||
|
const nghttp2_nv *nva, size_t nvlen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
|
|
|
@ -585,19 +585,6 @@ nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
||||||
return iv_copy;
|
return iv_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_frame_nv_check_null(const char **nv)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
for(i = 0; nv[i]; i += 2) {
|
|
||||||
if(nv[i+1] == NULL ||
|
|
||||||
!nghttp2_check_header_name_nocase((const uint8_t*)nv[i],
|
|
||||||
strlen(nv[i]))) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nghttp2_nv_array_check_null(const nghttp2_nv *nva, size_t nvlen)
|
int nghttp2_nv_array_check_null(const nghttp2_nv *nva, size_t nvlen)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -665,50 +652,6 @@ void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen)
|
||||||
qsort(nva, nvlen, sizeof(nghttp2_nv), nv_compar);
|
qsort(nva, nvlen, sizeof(nghttp2_nv), nv_compar);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint8_t *data;
|
|
||||||
size_t buflen = 0, nvlen = 0;
|
|
||||||
nghttp2_nv *p;
|
|
||||||
for(i = 0; nv[i]; ++i) {
|
|
||||||
size_t len = strlen(nv[i]);
|
|
||||||
if(len > NGHTTP2_MAX_HD_VALUE_LENGTH) {
|
|
||||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
buflen += len;
|
|
||||||
}
|
|
||||||
nvlen = i/2;
|
|
||||||
/* If all name/value pair is 0-length, remove them */
|
|
||||||
if(nvlen == 0 || buflen == 0) {
|
|
||||||
*nva_ptr = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
buflen += sizeof(nghttp2_nv)*nvlen;
|
|
||||||
*nva_ptr = malloc(buflen);
|
|
||||||
if(*nva_ptr == NULL) {
|
|
||||||
return NGHTTP2_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
p = *nva_ptr;
|
|
||||||
data = (uint8_t*)(*nva_ptr) + sizeof(nghttp2_nv)*nvlen;
|
|
||||||
|
|
||||||
for(i = 0; nv[i]; i += 2) {
|
|
||||||
size_t len = strlen(nv[i]);
|
|
||||||
memcpy(data, nv[i], len);
|
|
||||||
p->name = data;
|
|
||||||
p->namelen = len;
|
|
||||||
nghttp2_downcase(p->name, p->namelen);
|
|
||||||
data += len;
|
|
||||||
len = strlen(nv[i+1]);
|
|
||||||
memcpy(data, nv[i+1], len);
|
|
||||||
p->value = data;
|
|
||||||
p->valuelen = len;
|
|
||||||
data += len;
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
return nvlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t nghttp2_nv_array_copy(nghttp2_nv **nva_ptr,
|
ssize_t nghttp2_nv_array_copy(nghttp2_nv **nva_ptr,
|
||||||
const nghttp2_nv *nva, size_t nvlen)
|
const nghttp2_nv *nva, size_t nvlen)
|
||||||
{
|
{
|
||||||
|
|
|
@ -514,37 +514,12 @@ void nghttp2_frame_data_free(nghttp2_data *frame);
|
||||||
nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
||||||
size_t niv);
|
size_t niv);
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks names are not empty string and do not contain control
|
|
||||||
* characters and values are not NULL.
|
|
||||||
*
|
|
||||||
* This function returns nonzero if it succeeds, or 0.
|
|
||||||
*/
|
|
||||||
int nghttp2_frame_nv_check_null(const char **nv);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sorts the |nva| in ascending order of name and value. If names are
|
* Sorts the |nva| in ascending order of name and value. If names are
|
||||||
* equivalent, sort them by value.
|
* equivalent, sort them by value.
|
||||||
*/
|
*/
|
||||||
void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
|
void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
|
||||||
|
|
||||||
/*
|
|
||||||
* Copies name/value pairs from |nv| to |*nva_ptr|, which is
|
|
||||||
* dynamically allocated so that all items can be stored.
|
|
||||||
*
|
|
||||||
* The |*nva_ptr| must be freed using nghttp2_nv_array_del().
|
|
||||||
*
|
|
||||||
* This function returns the number of name/value pairs in |*nva_ptr|,
|
|
||||||
* or one of the following negative error codes:
|
|
||||||
*
|
|
||||||
* NGHTTP2_ERR_NOMEM
|
|
||||||
* Out of memory.
|
|
||||||
* NGHTTP2_ERR_INVALID_ARGUMENT
|
|
||||||
* The length of name or value in |nv| is strictly larger than
|
|
||||||
* NGHTTP2_MAX_HD_VALUE_LENGTH.
|
|
||||||
*/
|
|
||||||
ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copies name/value pairs from |nva|, which contains |nvlen| pairs,
|
* Copies name/value pairs from |nva|, which contains |nvlen| pairs,
|
||||||
* to |*nva_ptr|, which is dynamically allocated so that all items can
|
* to |*nva_ptr|, which is dynamically allocated so that all items can
|
||||||
|
|
|
@ -98,29 +98,6 @@ static int nghttp2_submit_headers_shared
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nghttp2_submit_headers_shared_nv
|
|
||||||
(nghttp2_session *session,
|
|
||||||
uint8_t flags,
|
|
||||||
int32_t stream_id,
|
|
||||||
int32_t pri,
|
|
||||||
const char **nv,
|
|
||||||
const nghttp2_data_provider *data_prd,
|
|
||||||
void *stream_user_data)
|
|
||||||
{
|
|
||||||
ssize_t nvlen;
|
|
||||||
nghttp2_nv *nva_copy;
|
|
||||||
if(!nghttp2_frame_nv_check_null(nv)) {
|
|
||||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva_copy, nv);
|
|
||||||
if(nvlen < 0) {
|
|
||||||
return nvlen;
|
|
||||||
}
|
|
||||||
return nghttp2_submit_headers_shared(session, flags, stream_id,
|
|
||||||
pri, nva_copy, nvlen, data_prd,
|
|
||||||
stream_user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nghttp2_submit_headers_shared_nva
|
static int nghttp2_submit_headers_shared_nva
|
||||||
(nghttp2_session *session,
|
(nghttp2_session *session,
|
||||||
uint8_t flags,
|
uint8_t flags,
|
||||||
|
@ -147,10 +124,11 @@ static int nghttp2_submit_headers_shared_nva
|
||||||
|
|
||||||
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
||||||
int32_t stream_id, int32_t pri,
|
int32_t stream_id, int32_t pri,
|
||||||
const char **nv, void *stream_user_data)
|
const nghttp2_nv *nva, size_t nvlen,
|
||||||
|
void *stream_user_data)
|
||||||
{
|
{
|
||||||
return nghttp2_submit_headers_shared_nv(session, flags, stream_id,
|
return nghttp2_submit_headers_shared_nva(session, flags, stream_id, pri,
|
||||||
pri, nv, NULL, stream_user_data);
|
nva, nvlen, NULL, stream_user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,35 +191,35 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
||||||
int32_t stream_id, const char **nv)
|
int32_t stream_id,
|
||||||
|
const nghttp2_nv *nva, size_t nvlen)
|
||||||
{
|
{
|
||||||
nghttp2_frame *frame;
|
nghttp2_frame *frame;
|
||||||
nghttp2_nv *nva;
|
nghttp2_nv *nva_copy;
|
||||||
ssize_t nvlen;
|
|
||||||
uint8_t flags_copy;
|
uint8_t flags_copy;
|
||||||
int r;
|
int rv;
|
||||||
|
|
||||||
|
if(!nghttp2_nv_array_check_null(nva, nvlen)) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
if(nghttp2_session_get_stream(session, stream_id) == NULL) {
|
if(nghttp2_session_get_stream(session, stream_id) == NULL) {
|
||||||
return NGHTTP2_ERR_STREAM_CLOSED;
|
return NGHTTP2_ERR_STREAM_CLOSED;
|
||||||
}
|
}
|
||||||
if(!nghttp2_frame_nv_check_null(nv)) {
|
|
||||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
frame = malloc(sizeof(nghttp2_frame));
|
frame = malloc(sizeof(nghttp2_frame));
|
||||||
if(frame == NULL) {
|
if(frame == NULL) {
|
||||||
return NGHTTP2_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
|
rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen);
|
||||||
if(nvlen < 0) {
|
if(rv < 0) {
|
||||||
free(frame);
|
free(frame);
|
||||||
return nvlen;
|
return rv;
|
||||||
}
|
}
|
||||||
/* TODO Implement header continuation */
|
/* TODO Implement header continuation */
|
||||||
flags_copy = NGHTTP2_FLAG_END_PUSH_PROMISE;
|
flags_copy = NGHTTP2_FLAG_END_PUSH_PROMISE;
|
||||||
nghttp2_frame_push_promise_init(&frame->push_promise, flags_copy,
|
nghttp2_frame_push_promise_init(&frame->push_promise, flags_copy,
|
||||||
stream_id, -1, nva, nvlen);
|
stream_id, -1, nva_copy, nvlen);
|
||||||
r = nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL);
|
rv = nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL);
|
||||||
if(r != 0) {
|
if(rv != 0) {
|
||||||
nghttp2_frame_push_promise_free(&frame->push_promise);
|
nghttp2_frame_push_promise_free(&frame->push_promise);
|
||||||
free(frame);
|
free(frame);
|
||||||
}
|
}
|
||||||
|
@ -307,19 +285,9 @@ static uint8_t set_request_flags(int32_t pri,
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_submit_request(nghttp2_session *session, int32_t pri,
|
int nghttp2_submit_request(nghttp2_session *session, int32_t pri,
|
||||||
const char **nv,
|
const nghttp2_nv *nva, size_t nvlen,
|
||||||
const nghttp2_data_provider *data_prd,
|
const nghttp2_data_provider *data_prd,
|
||||||
void *stream_user_data)
|
void *stream_user_data)
|
||||||
{
|
|
||||||
uint8_t flags = set_request_flags(pri, data_prd);
|
|
||||||
return nghttp2_submit_headers_shared_nv(session, flags, -1, pri, nv,
|
|
||||||
data_prd, stream_user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
int nghttp2_submit_request2(nghttp2_session *session, int32_t pri,
|
|
||||||
const nghttp2_nv *nva, size_t nvlen,
|
|
||||||
const nghttp2_data_provider *data_prd,
|
|
||||||
void *stream_user_data)
|
|
||||||
{
|
{
|
||||||
uint8_t flags = set_request_flags(pri, data_prd);
|
uint8_t flags = set_request_flags(pri, data_prd);
|
||||||
return nghttp2_submit_headers_shared_nva(session, flags, -1, pri, nva, nvlen,
|
return nghttp2_submit_headers_shared_nva(session, flags, -1, pri, nva, nvlen,
|
||||||
|
@ -336,19 +304,9 @@ static uint8_t set_response_flags(const nghttp2_data_provider *data_prd)
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_submit_response(nghttp2_session *session,
|
int nghttp2_submit_response(nghttp2_session *session,
|
||||||
int32_t stream_id, const char **nv,
|
int32_t stream_id,
|
||||||
|
const nghttp2_nv *nva, size_t nvlen,
|
||||||
const nghttp2_data_provider *data_prd)
|
const nghttp2_data_provider *data_prd)
|
||||||
{
|
|
||||||
uint8_t flags = set_response_flags(data_prd);
|
|
||||||
return nghttp2_submit_headers_shared_nv(session, flags, stream_id,
|
|
||||||
NGHTTP2_PRI_DEFAULT, nv, data_prd,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int nghttp2_submit_response2(nghttp2_session *session,
|
|
||||||
int32_t stream_id,
|
|
||||||
const nghttp2_nv *nva, size_t nvlen,
|
|
||||||
const nghttp2_data_provider *data_prd)
|
|
||||||
{
|
{
|
||||||
uint8_t flags = set_response_flags(data_prd);
|
uint8_t flags = set_response_flags(data_prd);
|
||||||
return nghttp2_submit_headers_shared_nva(session, flags, stream_id,
|
return nghttp2_submit_headers_shared_nva(session, flags, stream_id,
|
||||||
|
|
|
@ -454,21 +454,19 @@ int Http2Handler::submit_file_response(const std::string& status,
|
||||||
std::string date_str = util::http_date(time(0));
|
std::string date_str = util::http_date(time(0));
|
||||||
std::string content_length = util::to_str(file_length);
|
std::string content_length = util::to_str(file_length);
|
||||||
std::string last_modified_str;
|
std::string last_modified_str;
|
||||||
const char *nv[] = {
|
auto nva = std::vector<nghttp2_nv>{
|
||||||
":status", status.c_str(),
|
MAKE_NV_LS(":status", status),
|
||||||
"server", NGHTTPD_SERVER.c_str(),
|
MAKE_NV_LS("server", NGHTTPD_SERVER),
|
||||||
"content-length", content_length.c_str(),
|
MAKE_NV_LS("content-length", content_length),
|
||||||
"cache-control", "max-age=3600",
|
MAKE_NV_LS_LS("cache-control", "max-age=3600"),
|
||||||
"date", date_str.c_str(),
|
MAKE_NV_LS("date", date_str),
|
||||||
nullptr, nullptr,
|
|
||||||
nullptr
|
|
||||||
};
|
};
|
||||||
if(last_modified != 0) {
|
if(last_modified != 0) {
|
||||||
last_modified_str = util::http_date(last_modified);
|
last_modified_str = util::http_date(last_modified);
|
||||||
nv[10] = "last-modified";
|
nva.push_back(MAKE_NV_LS("last-modified", last_modified_str));
|
||||||
nv[11] = last_modified_str.c_str();
|
|
||||||
}
|
}
|
||||||
return nghttp2_submit_response(session_, stream_id, nv, data_prd);
|
return nghttp2_submit_response(session_, stream_id, nva.data(), nva.size(),
|
||||||
|
data_prd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Http2Handler::submit_response
|
int Http2Handler::submit_response
|
||||||
|
@ -478,21 +476,16 @@ int Http2Handler::submit_response
|
||||||
nghttp2_data_provider *data_prd)
|
nghttp2_data_provider *data_prd)
|
||||||
{
|
{
|
||||||
std::string date_str = util::http_date(time(0));
|
std::string date_str = util::http_date(time(0));
|
||||||
const size_t static_size = 6;
|
auto nva = std::vector<nghttp2_nv>{
|
||||||
auto nv = std::vector<const char*>();
|
MAKE_NV_LS(":status", status),
|
||||||
nv.reserve(static_size + headers.size() * 2 + 1);
|
MAKE_NV_LS("server", NGHTTPD_SERVER),
|
||||||
nv.push_back(":status");
|
MAKE_NV_LS("date", date_str)
|
||||||
nv.push_back(status.c_str());
|
};
|
||||||
nv.push_back("server");
|
|
||||||
nv.push_back(NGHTTPD_SERVER.c_str());
|
|
||||||
nv.push_back("date");
|
|
||||||
nv.push_back(date_str.c_str());
|
|
||||||
for(size_t i = 0; i < headers.size(); ++i) {
|
for(size_t i = 0; i < headers.size(); ++i) {
|
||||||
nv.push_back(headers[i].first.c_str());
|
nva.push_back(http2::make_nv(headers[i].first, headers[i].second));
|
||||||
nv.push_back(headers[i].second.c_str());
|
|
||||||
}
|
}
|
||||||
nv.push_back(nullptr);
|
int r = nghttp2_submit_response(session_, stream_id, nva.data(), nva.size(),
|
||||||
int r = nghttp2_submit_response(session_, stream_id, nv.data(), data_prd);
|
data_prd);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,12 +493,12 @@ int Http2Handler::submit_response(const std::string& status,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
nghttp2_data_provider *data_prd)
|
nghttp2_data_provider *data_prd)
|
||||||
{
|
{
|
||||||
const char *nv[] = {
|
auto nva = std::vector<nghttp2_nv>{
|
||||||
":status", status.c_str(),
|
MAKE_NV_LS(":status", status),
|
||||||
"server", NGHTTPD_SERVER.c_str(),
|
MAKE_NV_LS("server", NGHTTPD_SERVER)
|
||||||
nullptr
|
|
||||||
};
|
};
|
||||||
return nghttp2_submit_response(session_, stream_id, nv, data_prd);
|
return nghttp2_submit_response(session_, stream_id, nva.data(), nva.size(),
|
||||||
|
data_prd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Http2Handler::add_stream(int32_t stream_id, std::unique_ptr<Request> req)
|
void Http2Handler::add_stream(int32_t stream_id, std::unique_ptr<Request> req)
|
||||||
|
|
|
@ -50,6 +50,10 @@ namespace http2 {
|
||||||
{ (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) }
|
||||||
|
|
||||||
|
// Create nghttp2_nv from string literal |NAME| and c-string |VALUE|.
|
||||||
|
#define MAKE_NV_LS_CS(NAME, VALUE) \
|
||||||
|
{ (uint8_t*)NAME, (uint8_t*)VALUE, \
|
||||||
|
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(strlen(VALUE)) }
|
||||||
|
|
||||||
std::string get_status_string(unsigned int status_code);
|
std::string get_status_string(unsigned int status_code);
|
||||||
|
|
||||||
|
|
|
@ -965,8 +965,8 @@ int submit_request
|
||||||
for(auto& kv : build_headers) {
|
for(auto& kv : build_headers) {
|
||||||
nva.push_back(http2::make_nv(kv.first, kv.second));
|
nva.push_back(http2::make_nv(kv.first, kv.second));
|
||||||
}
|
}
|
||||||
int rv = nghttp2_submit_request2(client->session, req->pri,
|
int rv = nghttp2_submit_request(client->session, req->pri,
|
||||||
nva.data(), nva.size(), req->data_prd, req);
|
nva.data(), nva.size(), req->data_prd, req);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
std::cerr << "nghttp2_submit_request() returned error: "
|
std::cerr << "nghttp2_submit_request() returned error: "
|
||||||
<< nghttp2_strerror(rv) << std::endl;
|
<< nghttp2_strerror(rv) << std::endl;
|
||||||
|
|
|
@ -575,8 +575,8 @@ int Http2Session::submit_request(Http2DownstreamConnection *dconn,
|
||||||
{
|
{
|
||||||
assert(state_ == CONNECTED);
|
assert(state_ == CONNECTED);
|
||||||
auto sd = util::make_unique<StreamData>();
|
auto sd = util::make_unique<StreamData>();
|
||||||
int rv = nghttp2_submit_request2(session_, pri, nva, nvlen,
|
int rv = nghttp2_submit_request(session_, pri, nva, nvlen,
|
||||||
data_prd, sd.get());
|
data_prd, sd.get());
|
||||||
if(rv == 0) {
|
if(rv == 0) {
|
||||||
dconn->attach_stream_data(sd.get());
|
dconn->attach_stream_data(sd.get());
|
||||||
streams_.insert(sd.release());
|
streams_.insert(sd.release());
|
||||||
|
|
|
@ -878,16 +878,15 @@ int Http2Upstream::error_reply(Downstream *downstream,
|
||||||
|
|
||||||
auto content_length = util::utos(html.size());
|
auto content_length = util::utos(html.size());
|
||||||
auto status_code_str = util::utos(status_code);
|
auto status_code_str = util::utos(status_code);
|
||||||
const char *nv[] = {
|
auto nva = std::vector<nghttp2_nv>{
|
||||||
":status", status_code_str.c_str(),
|
MAKE_NV_LS(":status", status_code_str),
|
||||||
"content-type", "text/html; charset=UTF-8",
|
MAKE_NV_LS_LS("content-type", "text/html; charset=UTF-8"),
|
||||||
"server", get_config()->server_name,
|
MAKE_NV_LS_CS("server", get_config()->server_name),
|
||||||
"content-length", content_length.c_str(),
|
MAKE_NV_LS("content-length", content_length)
|
||||||
nullptr
|
|
||||||
};
|
};
|
||||||
|
|
||||||
rv = nghttp2_submit_response(session_, downstream->get_stream_id(), nv,
|
rv = nghttp2_submit_response(session_, downstream->get_stream_id(),
|
||||||
&data_prd);
|
nva.data(), nva.size(), &data_prd);
|
||||||
if(rv < NGHTTP2_ERR_FATAL) {
|
if(rv < NGHTTP2_ERR_FATAL) {
|
||||||
ULOG(FATAL, this) << "nghttp2_submit_response() failed: "
|
ULOG(FATAL, this) << "nghttp2_submit_response() failed: "
|
||||||
<< nghttp2_strerror(rv);
|
<< nghttp2_strerror(rv);
|
||||||
|
@ -992,8 +991,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream)
|
||||||
data_prd.read_callback = downstream_data_read_callback;
|
data_prd.read_callback = downstream_data_read_callback;
|
||||||
|
|
||||||
int rv;
|
int rv;
|
||||||
rv = nghttp2_submit_response2(session_, downstream->get_stream_id(),
|
rv = nghttp2_submit_response(session_, downstream->get_stream_id(),
|
||||||
nva.data(), nva.size(), &data_prd);
|
nva.data(), nva.size(), &data_prd);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
ULOG(FATAL, this) << "nghttp2_submit_response() failed";
|
ULOG(FATAL, this) << "nghttp2_submit_response() failed";
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -114,9 +114,10 @@ static void run_nghttp2_session_send(void)
|
||||||
{
|
{
|
||||||
nghttp2_session *session;
|
nghttp2_session *session;
|
||||||
nghttp2_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
const char *nv[] = { ":host", "example.org",
|
nghttp2_nv nv[] = {
|
||||||
":scheme", "https",
|
MAKE_NV(":host", "example.org"),
|
||||||
NULL };
|
MAKE_NV(":scheme", "https")
|
||||||
|
};
|
||||||
nghttp2_data_provider data_prd;
|
nghttp2_data_provider data_prd;
|
||||||
nghttp2_settings_entry iv[2];
|
nghttp2_settings_entry iv[2];
|
||||||
my_user_data ud;
|
my_user_data ud;
|
||||||
|
@ -136,12 +137,12 @@ static void run_nghttp2_session_send(void)
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto client_new_fail;
|
goto client_new_fail;
|
||||||
}
|
}
|
||||||
rv = nghttp2_submit_request(session, 3, nv, &data_prd, NULL);
|
rv = nghttp2_submit_request(session, 3, nv, ARRLEN(nv), &data_prd, NULL);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1,
|
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1,
|
||||||
NGHTTP2_PRI_DEFAULT, nv, NULL);
|
NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +153,7 @@ static void run_nghttp2_session_send(void)
|
||||||
/* The HEADERS submitted by the previous nghttp2_submit_headers will
|
/* The HEADERS submitted by the previous nghttp2_submit_headers will
|
||||||
have stream ID 3. Send HEADERS to that stream. */
|
have stream ID 3. Send HEADERS to that stream. */
|
||||||
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
|
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
|
||||||
NGHTTP2_PRI_DEFAULT, nv, NULL);
|
NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +176,7 @@ static void run_nghttp2_session_send(void)
|
||||||
}
|
}
|
||||||
/* Sending against half-closed stream */
|
/* Sending against half-closed stream */
|
||||||
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
|
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
|
||||||
NGHTTP2_PRI_DEFAULT, nv, NULL);
|
NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -224,9 +225,10 @@ static void run_nghttp2_session_recv(void)
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
ssize_t framelen;
|
ssize_t framelen;
|
||||||
const char *nv[] = { ":authority", "example.org",
|
nghttp2_nv nv[] = {
|
||||||
":scheme", "https",
|
MAKE_NV(":authority", "example.org"),
|
||||||
NULL };
|
MAKE_NV(":scheme", "https")
|
||||||
|
};
|
||||||
nghttp2_settings_entry iv[2];
|
nghttp2_settings_entry iv[2];
|
||||||
my_user_data ud;
|
my_user_data ud;
|
||||||
data_feed df;
|
data_feed df;
|
||||||
|
@ -239,13 +241,13 @@ static void run_nghttp2_session_recv(void)
|
||||||
ud.df = &df;
|
ud.df = &df;
|
||||||
|
|
||||||
nghttp2_failmalloc_pause();
|
nghttp2_failmalloc_pause();
|
||||||
|
nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
|
||||||
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||||
nghttp2_session_server_new(&session, &callbacks, &ud);
|
nghttp2_session_server_new(&session, &callbacks, &ud);
|
||||||
nghttp2_failmalloc_unpause();
|
nghttp2_failmalloc_unpause();
|
||||||
|
|
||||||
/* HEADERS */
|
/* HEADERS */
|
||||||
nghttp2_failmalloc_pause();
|
nghttp2_failmalloc_pause();
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
|
|
||||||
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM,
|
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM,
|
||||||
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
|
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
|
||||||
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame.headers,
|
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame.headers,
|
||||||
|
@ -319,9 +321,10 @@ static void run_nghttp2_frame_pack_headers(void)
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
ssize_t framelen;
|
ssize_t framelen;
|
||||||
const char *nv[] = { ":host", "example.org",
|
nghttp2_nv nv[] = {
|
||||||
":scheme", "https",
|
MAKE_NV(":host", "example.org"),
|
||||||
NULL };
|
MAKE_NV(":scheme", "https")
|
||||||
|
};
|
||||||
int rv;
|
int rv;
|
||||||
nghttp2_nv *nva;
|
nghttp2_nv *nva;
|
||||||
ssize_t nvlen;
|
ssize_t nvlen;
|
||||||
|
@ -334,7 +337,7 @@ static void run_nghttp2_frame_pack_headers(void)
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto inflate_init_fail;
|
goto inflate_init_fail;
|
||||||
}
|
}
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
|
nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
|
||||||
if(nvlen < 0) {
|
if(nvlen < 0) {
|
||||||
goto nv_copy_fail;
|
goto nv_copy_fail;
|
||||||
}
|
}
|
||||||
|
|
19
tests/main.c
19
tests/main.c
|
@ -128,21 +128,14 @@ int main(int argc, char* argv[])
|
||||||
!CU_add_test(pSuite, "session_upgrade", test_nghttp2_session_upgrade) ||
|
!CU_add_test(pSuite, "session_upgrade", test_nghttp2_session_upgrade) ||
|
||||||
!CU_add_test(pSuite, "session_reprioritize_stream",
|
!CU_add_test(pSuite, "session_reprioritize_stream",
|
||||||
test_nghttp2_session_reprioritize_stream) ||
|
test_nghttp2_session_reprioritize_stream) ||
|
||||||
!CU_add_test(pSuite, "submit_response", test_nghttp2_submit_response) ||
|
|
||||||
!CU_add_test(pSuite, "submit_response_without_data",
|
|
||||||
test_nghttp2_submit_response_without_data) ||
|
|
||||||
!CU_add_test(pSuite, "submit_request_with_data",
|
!CU_add_test(pSuite, "submit_request_with_data",
|
||||||
test_nghttp2_submit_request_with_data) ||
|
test_nghttp2_submit_request_with_data) ||
|
||||||
!CU_add_test(pSuite, "submit_request_without_data",
|
!CU_add_test(pSuite, "submit_request_without_data",
|
||||||
test_nghttp2_submit_request_without_data) ||
|
test_nghttp2_submit_request_without_data) ||
|
||||||
!CU_add_test(pSuite, "submit_request2_with_data",
|
!CU_add_test(pSuite, "submit_response_with_data",
|
||||||
test_nghttp2_submit_request2_with_data) ||
|
test_nghttp2_submit_response_with_data) ||
|
||||||
!CU_add_test(pSuite, "submit_request2_without_data",
|
!CU_add_test(pSuite, "submit_response_without_data",
|
||||||
test_nghttp2_submit_request2_without_data) ||
|
test_nghttp2_submit_response_without_data) ||
|
||||||
!CU_add_test(pSuite, "submit_response2_with_data",
|
|
||||||
test_nghttp2_submit_response2_with_data) ||
|
|
||||||
!CU_add_test(pSuite, "submit_response2_without_data",
|
|
||||||
test_nghttp2_submit_response2_without_data) ||
|
|
||||||
!CU_add_test(pSuite, "submit_headers_start_stream",
|
!CU_add_test(pSuite, "submit_headers_start_stream",
|
||||||
test_nghttp2_submit_headers_start_stream) ||
|
test_nghttp2_submit_headers_start_stream) ||
|
||||||
!CU_add_test(pSuite, "submit_headers_reply",
|
!CU_add_test(pSuite, "submit_headers_reply",
|
||||||
|
@ -205,8 +198,6 @@ int main(int argc, char* argv[])
|
||||||
test_nghttp2_session_data_backoff_by_high_pri_frame) ||
|
test_nghttp2_session_data_backoff_by_high_pri_frame) ||
|
||||||
!CU_add_test(pSuite, "pack_settings_payload",
|
!CU_add_test(pSuite, "pack_settings_payload",
|
||||||
test_nghttp2_pack_settings_payload) ||
|
test_nghttp2_pack_settings_payload) ||
|
||||||
!CU_add_test(pSuite, "frame_nv_check_null",
|
|
||||||
test_nghttp2_frame_nv_check_null) ||
|
|
||||||
!CU_add_test(pSuite, "frame_pack_headers",
|
!CU_add_test(pSuite, "frame_pack_headers",
|
||||||
test_nghttp2_frame_pack_headers) ||
|
test_nghttp2_frame_pack_headers) ||
|
||||||
!CU_add_test(pSuite, "frame_pack_headers_frame_too_large",
|
!CU_add_test(pSuite, "frame_pack_headers_frame_too_large",
|
||||||
|
@ -226,8 +217,6 @@ int main(int argc, char* argv[])
|
||||||
test_nghttp2_frame_pack_window_update) ||
|
test_nghttp2_frame_pack_window_update) ||
|
||||||
!CU_add_test(pSuite, "nv_array_check_null",
|
!CU_add_test(pSuite, "nv_array_check_null",
|
||||||
test_nghttp2_nv_array_check_null) ||
|
test_nghttp2_nv_array_check_null) ||
|
||||||
!CU_add_test(pSuite, "nv_array_from_cstr",
|
|
||||||
test_nghttp2_nv_array_from_cstr) ||
|
|
||||||
!CU_add_test(pSuite, "nv_array_copy", test_nghttp2_nv_array_copy) ||
|
!CU_add_test(pSuite, "nv_array_copy", test_nghttp2_nv_array_copy) ||
|
||||||
!CU_add_test(pSuite, "iv_check", test_nghttp2_iv_check) ||
|
!CU_add_test(pSuite, "iv_check", test_nghttp2_iv_check) ||
|
||||||
!CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) ||
|
!CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) ||
|
||||||
|
|
|
@ -33,28 +33,29 @@
|
||||||
#include "nghttp2_helper.h"
|
#include "nghttp2_helper.h"
|
||||||
#include "nghttp2_test_helper.h"
|
#include "nghttp2_test_helper.h"
|
||||||
|
|
||||||
static const char *headers[] = {
|
static nghttp2_nv make_nv(const char *name, const char *value)
|
||||||
"method", "GET",
|
|
||||||
"scheme", "https",
|
|
||||||
"url", "/",
|
|
||||||
"x-head", "foo",
|
|
||||||
"x-head", "bar",
|
|
||||||
"version", "HTTP/1.1",
|
|
||||||
"x-empty", "",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
void test_nghttp2_frame_nv_check_null(void)
|
|
||||||
{
|
{
|
||||||
const char *headers1[] = { "path", "/", "host", "a", NULL };
|
nghttp2_nv nv;
|
||||||
const char *headers2[] = { "", "/", "host", "a", NULL };
|
nv.name = (uint8_t*)name;
|
||||||
const char *headers3[] = { "path", "/", "host\x01", "a", NULL };
|
nv.value = (uint8_t*)value;
|
||||||
const char *headers4[] = { "PATH", "/", "host", NULL, NULL };
|
nv.namelen = strlen(name);
|
||||||
|
nv.valuelen = strlen(value);
|
||||||
|
return nv;
|
||||||
|
}
|
||||||
|
|
||||||
CU_ASSERT(nghttp2_frame_nv_check_null(headers1));
|
#define HEADERS_LENGTH 7
|
||||||
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers2));
|
|
||||||
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers3));
|
static nghttp2_nv* headers(void)
|
||||||
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers4));
|
{
|
||||||
|
nghttp2_nv *nva = malloc(sizeof(nghttp2_nv) * HEADERS_LENGTH);
|
||||||
|
nva[0] = make_nv("method", "GET");
|
||||||
|
nva[1] = make_nv("scheme", "https");
|
||||||
|
nva[2] = make_nv("url", "/");
|
||||||
|
nva[3] = make_nv("x-head", "foo");
|
||||||
|
nva[4] = make_nv("x-head", "bar");
|
||||||
|
nva[5] = make_nv("version", "HTTP/1.1");
|
||||||
|
nva[6] = make_nv("x-empty", "");
|
||||||
|
return nva;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_frame_header(uint16_t length, uint8_t type, uint8_t flags,
|
static void check_frame_header(uint16_t length, uint8_t type, uint8_t flags,
|
||||||
|
@ -79,7 +80,8 @@ void test_nghttp2_frame_pack_headers()
|
||||||
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||||
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
|
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||||
|
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
|
nva = headers();
|
||||||
|
nvlen = HEADERS_LENGTH;
|
||||||
nghttp2_frame_headers_init(&frame,
|
nghttp2_frame_headers_init(&frame,
|
||||||
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
||||||
1000000007,
|
1000000007,
|
||||||
|
@ -138,19 +140,20 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
|
||||||
nghttp2_nv *nva;
|
nghttp2_nv *nva;
|
||||||
ssize_t nvlen;
|
ssize_t nvlen;
|
||||||
size_t big_vallen = NGHTTP2_MAX_HD_VALUE_LENGTH;
|
size_t big_vallen = NGHTTP2_MAX_HD_VALUE_LENGTH;
|
||||||
char *big_hds[17];
|
nghttp2_nv big_hds[8];
|
||||||
size_t big_hdslen = sizeof(big_hds)/sizeof(big_hds[0]) - 1;
|
size_t big_hdslen = ARRLEN(big_hds);
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for(i = 0; i < big_hdslen; i += 2) {
|
for(i = 0; i < big_hdslen; ++i) {
|
||||||
big_hds[i] = (char*)"header";
|
big_hds[i].name = (uint8_t*)"header";
|
||||||
big_hds[i+1] = malloc(big_vallen+1);
|
big_hds[i].value = malloc(big_vallen+1);
|
||||||
memset(big_hds[i+1], '0'+i, big_vallen);
|
memset(big_hds[i].value, '0'+i, big_vallen);
|
||||||
big_hds[i+1][big_vallen] = '\0';
|
big_hds[i].value[big_vallen] = '\0';
|
||||||
|
big_hds[i].namelen = strlen((char*)big_hds[i].name);
|
||||||
|
big_hds[i].valuelen = big_vallen;
|
||||||
}
|
}
|
||||||
big_hds[big_hdslen] = NULL;
|
|
||||||
|
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva, (const char**)big_hds);
|
nvlen = nghttp2_nv_array_copy(&nva, big_hds, big_hdslen);
|
||||||
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||||
nghttp2_frame_headers_init(&frame,
|
nghttp2_frame_headers_init(&frame,
|
||||||
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
||||||
|
@ -161,8 +164,8 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
|
||||||
|
|
||||||
nghttp2_frame_headers_free(&frame);
|
nghttp2_frame_headers_free(&frame);
|
||||||
free(buf);
|
free(buf);
|
||||||
for(i = 0; i < big_hdslen; i += 2) {
|
for(i = 0; i < big_hdslen; ++i) {
|
||||||
free(big_hds[i+1]);
|
free(big_hds[i].value);
|
||||||
}
|
}
|
||||||
nghttp2_hd_deflate_free(&deflater);
|
nghttp2_hd_deflate_free(&deflater);
|
||||||
}
|
}
|
||||||
|
@ -260,7 +263,8 @@ void test_nghttp2_frame_pack_push_promise()
|
||||||
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_RESPONSE);
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_RESPONSE);
|
||||||
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_RESPONSE);
|
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_RESPONSE);
|
||||||
|
|
||||||
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
|
nva = headers();
|
||||||
|
nvlen = HEADERS_LENGTH;
|
||||||
nghttp2_frame_push_promise_init(&frame, NGHTTP2_FLAG_END_PUSH_PROMISE,
|
nghttp2_frame_push_promise_init(&frame, NGHTTP2_FLAG_END_PUSH_PROMISE,
|
||||||
1000000007, (1U << 31) - 1, nva, nvlen);
|
1000000007, (1U << 31) - 1, nva, nvlen);
|
||||||
framelen = nghttp2_frame_pack_push_promise(&buf, &buflen, &frame, &deflater);
|
framelen = nghttp2_frame_pack_push_promise(&buf, &buflen, &frame, &deflater);
|
||||||
|
@ -373,48 +377,6 @@ void test_nghttp2_nv_array_check_null(void)
|
||||||
CU_ASSERT(nghttp2_nv_array_check_null(nva4, ARRLEN(nva4)));
|
CU_ASSERT(nghttp2_nv_array_check_null(nva4, ARRLEN(nva4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_nghttp2_nv_array_from_cstr(void)
|
|
||||||
{
|
|
||||||
const char *empty[] = {NULL};
|
|
||||||
const char *emptynv[] = {"", "", "", "", NULL};
|
|
||||||
const char *nv[] = {"alpha", "bravo", "charlie", "delta", NULL};
|
|
||||||
const char *bignv[] = {"echo", NULL, NULL};
|
|
||||||
size_t bigvallen = 64*1024;
|
|
||||||
char *bigval = malloc(bigvallen+1);
|
|
||||||
nghttp2_nv *nva;
|
|
||||||
ssize_t rv;
|
|
||||||
|
|
||||||
memset(bigval, '0', bigvallen);
|
|
||||||
bigval[bigvallen] = '\0';
|
|
||||||
bignv[1] = bigval;
|
|
||||||
|
|
||||||
rv = nghttp2_nv_array_from_cstr(&nva, empty);
|
|
||||||
CU_ASSERT(0 == rv);
|
|
||||||
CU_ASSERT(NULL == nva);
|
|
||||||
|
|
||||||
rv = nghttp2_nv_array_from_cstr(&nva, emptynv);
|
|
||||||
CU_ASSERT(0 == rv);
|
|
||||||
CU_ASSERT(NULL == nva);
|
|
||||||
|
|
||||||
rv = nghttp2_nv_array_from_cstr(&nva, nv);
|
|
||||||
CU_ASSERT(2 == rv);
|
|
||||||
CU_ASSERT(nva[0].namelen == 5);
|
|
||||||
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
|
|
||||||
CU_ASSERT(nva[0].valuelen = 5);
|
|
||||||
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
|
|
||||||
CU_ASSERT(nva[1].namelen == 7);
|
|
||||||
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
|
|
||||||
CU_ASSERT(nva[1].valuelen == 5);
|
|
||||||
CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));
|
|
||||||
|
|
||||||
nghttp2_nv_array_del(nva);
|
|
||||||
|
|
||||||
rv = nghttp2_nv_array_from_cstr(&nva, bignv);
|
|
||||||
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv);
|
|
||||||
|
|
||||||
free(bigval);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_nghttp2_nv_array_copy(void)
|
void test_nghttp2_nv_array_copy(void)
|
||||||
{
|
{
|
||||||
nghttp2_nv *nva;
|
nghttp2_nv *nva;
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#ifndef NGHTTP2_FRAME_TEST_H
|
#ifndef NGHTTP2_FRAME_TEST_H
|
||||||
#define NGHTTP2_FRAME_TEST_H
|
#define NGHTTP2_FRAME_TEST_H
|
||||||
|
|
||||||
void test_nghttp2_frame_nv_check_null(void);
|
|
||||||
void test_nghttp2_frame_pack_headers(void);
|
void test_nghttp2_frame_pack_headers(void);
|
||||||
void test_nghttp2_frame_pack_headers_frame_too_large(void);
|
void test_nghttp2_frame_pack_headers_frame_too_large(void);
|
||||||
void test_nghttp2_frame_pack_priority(void);
|
void test_nghttp2_frame_pack_priority(void);
|
||||||
|
@ -36,7 +35,6 @@ void test_nghttp2_frame_pack_ping(void);
|
||||||
void test_nghttp2_frame_pack_goaway(void);
|
void test_nghttp2_frame_pack_goaway(void);
|
||||||
void test_nghttp2_frame_pack_window_update(void);
|
void test_nghttp2_frame_pack_window_update(void);
|
||||||
void test_nghttp2_nv_array_check_null(void);
|
void test_nghttp2_nv_array_check_null(void);
|
||||||
void test_nghttp2_nv_array_from_cstr(void);
|
|
||||||
void test_nghttp2_nv_array_copy(void);
|
void test_nghttp2_nv_array_copy(void);
|
||||||
void test_nghttp2_iv_check(void);
|
void test_nghttp2_iv_check(void);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -53,14 +53,10 @@ void test_nghttp2_session_send_push_promise(void);
|
||||||
void test_nghttp2_session_is_my_stream_id(void);
|
void test_nghttp2_session_is_my_stream_id(void);
|
||||||
void test_nghttp2_session_upgrade(void);
|
void test_nghttp2_session_upgrade(void);
|
||||||
void test_nghttp2_session_reprioritize_stream(void);
|
void test_nghttp2_session_reprioritize_stream(void);
|
||||||
void test_nghttp2_submit_response(void);
|
|
||||||
void test_nghttp2_submit_response_without_data(void);
|
|
||||||
void test_nghttp2_submit_request_with_data(void);
|
void test_nghttp2_submit_request_with_data(void);
|
||||||
void test_nghttp2_submit_request_without_data(void);
|
void test_nghttp2_submit_request_without_data(void);
|
||||||
void test_nghttp2_submit_request2_with_data(void);
|
void test_nghttp2_submit_response_with_data(void);
|
||||||
void test_nghttp2_submit_request2_without_data(void);
|
void test_nghttp2_submit_response_without_data(void);
|
||||||
void test_nghttp2_submit_response2_with_data(void);
|
|
||||||
void test_nghttp2_submit_response2_without_data(void);
|
|
||||||
void test_nghttp2_submit_headers_start_stream(void);
|
void test_nghttp2_submit_headers_start_stream(void);
|
||||||
void test_nghttp2_submit_headers_reply(void);
|
void test_nghttp2_submit_headers_reply(void);
|
||||||
void test_nghttp2_submit_headers_push_reply(void);
|
void test_nghttp2_submit_headers_push_reply(void);
|
||||||
|
|
Loading…
Reference in New Issue