diff --git a/examples/client.c b/examples/client.c index ad7533e4..2bb8b1e5 100644 --- a/examples/client.c +++ b/examples/client.c @@ -51,6 +51,14 @@ enum { 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 { SSL *ssl; nghttp2_session *session; @@ -515,16 +523,17 @@ static void submit_request(struct Connection *connection, struct Request *req) { int pri = 0; int rv; - const char *nv[13]; - /* Make sure that the last item is NULL */ - nv[0] = ":method"; nv[1] = "GET"; - nv[2] = ":path"; nv[3] = req->path; - nv[4] = ":scheme"; nv[5] = "https"; - nv[6] = ":host"; nv[7] = req->hostport; - nv[8] = "accept"; nv[9] = "*/*"; - nv[10] = "user-agent"; nv[11] = "nghttp2/"NGHTTP2_VERSION; - nv[12] = NULL; - rv = nghttp2_submit_request(connection->session, pri, nv, NULL, req); + const nghttp2_nv nva[] = { + /* Make sure that the last item is NULL */ + MAKE_NV(":method", "GET"), + MAKE_NV_CS(":path", req->path), + MAKE_NV(":scheme", "https"), + MAKE_NV_CS(":host", req->hostport), + MAKE_NV("accept", "*/*"), + MAKE_NV("user-agent", "nghttp2/"NGHTTP2_VERSION) + }; + rv = nghttp2_submit_request(connection->session, pri, + nva, sizeof(nva)/sizeof(nva[0]), NULL, req); if(rv != 0) { diec("nghttp2_submit_request", rv); } diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 5f3ab991..d2f3adca 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -1764,27 +1764,20 @@ const char* nghttp2_strerror(int lib_error_code); * The |pri| is priority of this request. 0 is the highest priority * value and :macro:`NGHTTP2_PRI_LOWEST` is the lowest value. * - * The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]`` - * contains a pointer to the name string and ``nv[2*i+1]`` contains a - * 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``. + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. * * HTTP/2.0 specification has requirement about header fields in the * request HEADERS. See the specification for more details. * - * This function creates copies of all name/value pairs in |nv|. It - * also lower-cases all names in |nv|. - * - * The string in |nv| must be NULL-terminated. Use - * `nghttp2_submit_request2()` if name/value pairs are not - * NULL-terminated strings. + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. * * If |data_prd| is not ``NULL``, it provides data which will be sent * in subsequent DATA frames. In this case, a method that allows * request message bodies * (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 * copies the members of the |data_prd|. If |data_prd| is ``NULL``, * 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: * * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |pri| is invalid; or the |nv| includes empty name or - * ``NULL`` value. + * 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_request(nghttp2_session *session, int32_t pri, - const char **nv, + const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd, 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 * * Submits response HEADERS frame and optionally one or more DATA * frames against the stream |stream_id|. * - * The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]`` - * contains a pointer to the name string and ``nv[2*i+1]`` contains a - * 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``. + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. * * HTTP/2.0 specification has requirement about header fields in the * response HEADERS. See the specification for more details. * - * This function creates copies of all name/value pairs in |nv|. It - * also lower-cases all names in |nv|. + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. * * If |data_prd| is not ``NULL``, it provides data which will be sent * 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: * * :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` * Out of memory. */ 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); -/** - * @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 * @@ -1921,14 +1869,11 @@ int nghttp2_submit_response2(nghttp2_session *session, * * The |pri| is priority of this request. * - * The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]`` - * contains a pointer to the name string and ``nv[2*i+1]`` contains a - * 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``. + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. * - * This function creates copies of all name/value pairs in |nv|. It - * also lower-cases all names in |nv|. + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. * * 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 @@ -1943,13 +1888,14 @@ int nghttp2_submit_response2(nghttp2_session *session, * negative error codes: * * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * The |pri| is invalid; or the |nv| includes empty name or - * ``NULL`` value. + * 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_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); /** @@ -2059,14 +2005,11 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags, * * The |stream_id| must be client initiated stream ID. * - * The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]`` - * contains a pointer to the name string and ``nv[2*i+1]`` contains a - * 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``. + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. * - * This function creates copies of all name/value pairs in |nv|. It - * also lower-cases all names in |nv|. + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. * * Since the library reorders the frames and tries to send the highest * 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: * * :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` * The stream is already closed or does not exist. * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ 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 diff --git a/lib/nghttp2_frame.c b/lib/nghttp2_frame.c index eaf80299..843256e5 100644 --- a/lib/nghttp2_frame.c +++ b/lib/nghttp2_frame.c @@ -585,19 +585,6 @@ nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv, 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) { 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); } -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, const nghttp2_nv *nva, size_t nvlen) { diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index 7946c9d2..585876a1 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -514,37 +514,12 @@ void nghttp2_frame_data_free(nghttp2_data *frame); nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv, 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 * equivalent, sort them by value. */ 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, * to |*nva_ptr|, which is dynamically allocated so that all items can diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index 266b52ca..898ac07f 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -98,29 +98,6 @@ static int nghttp2_submit_headers_shared 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 (nghttp2_session *session, uint8_t flags, @@ -147,10 +124,11 @@ static int nghttp2_submit_headers_shared_nva int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags, 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, - pri, nv, NULL, stream_user_data); + return nghttp2_submit_headers_shared_nva(session, flags, stream_id, pri, + 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, - int32_t stream_id, const char **nv) + int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen) { nghttp2_frame *frame; - nghttp2_nv *nva; - ssize_t nvlen; + nghttp2_nv *nva_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) { return NGHTTP2_ERR_STREAM_CLOSED; } - if(!nghttp2_frame_nv_check_null(nv)) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } frame = malloc(sizeof(nghttp2_frame)); if(frame == NULL) { return NGHTTP2_ERR_NOMEM; } - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); - if(nvlen < 0) { + rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen); + if(rv < 0) { free(frame); - return nvlen; + return rv; } /* TODO Implement header continuation */ flags_copy = NGHTTP2_FLAG_END_PUSH_PROMISE; nghttp2_frame_push_promise_init(&frame->push_promise, flags_copy, - stream_id, -1, nva, nvlen); - r = nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); - if(r != 0) { + stream_id, -1, nva_copy, nvlen); + rv = nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); + if(rv != 0) { nghttp2_frame_push_promise_free(&frame->push_promise); 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, - const char **nv, + 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); - 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); 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, - int32_t stream_id, const char **nv, + 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); - 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); return nghttp2_submit_headers_shared_nva(session, flags, stream_id, diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 80f439c0..59be6c71 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -454,21 +454,19 @@ int Http2Handler::submit_file_response(const std::string& status, std::string date_str = util::http_date(time(0)); std::string content_length = util::to_str(file_length); std::string last_modified_str; - const char *nv[] = { - ":status", status.c_str(), - "server", NGHTTPD_SERVER.c_str(), - "content-length", content_length.c_str(), - "cache-control", "max-age=3600", - "date", date_str.c_str(), - nullptr, nullptr, - nullptr + auto nva = std::vector{ + MAKE_NV_LS(":status", status), + MAKE_NV_LS("server", NGHTTPD_SERVER), + MAKE_NV_LS("content-length", content_length), + MAKE_NV_LS_LS("cache-control", "max-age=3600"), + MAKE_NV_LS("date", date_str), }; if(last_modified != 0) { last_modified_str = util::http_date(last_modified); - nv[10] = "last-modified"; - nv[11] = last_modified_str.c_str(); + nva.push_back(MAKE_NV_LS("last-modified", last_modified_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 @@ -478,21 +476,16 @@ int Http2Handler::submit_response nghttp2_data_provider *data_prd) { std::string date_str = util::http_date(time(0)); - const size_t static_size = 6; - auto nv = std::vector(); - nv.reserve(static_size + headers.size() * 2 + 1); - nv.push_back(":status"); - 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()); + auto nva = std::vector{ + MAKE_NV_LS(":status", status), + MAKE_NV_LS("server", NGHTTPD_SERVER), + MAKE_NV_LS("date", date_str) + }; for(size_t i = 0; i < headers.size(); ++i) { - nv.push_back(headers[i].first.c_str()); - nv.push_back(headers[i].second.c_str()); + nva.push_back(http2::make_nv(headers[i].first, headers[i].second)); } - nv.push_back(nullptr); - int r = nghttp2_submit_response(session_, stream_id, nv.data(), data_prd); + int r = nghttp2_submit_response(session_, stream_id, nva.data(), nva.size(), + data_prd); return r; } @@ -500,12 +493,12 @@ int Http2Handler::submit_response(const std::string& status, int32_t stream_id, nghttp2_data_provider *data_prd) { - const char *nv[] = { - ":status", status.c_str(), - "server", NGHTTPD_SERVER.c_str(), - nullptr + auto nva = std::vector{ + MAKE_NV_LS(":status", status), + MAKE_NV_LS("server", NGHTTPD_SERVER) }; - 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 req) diff --git a/src/http2.h b/src/http2.h index 5f0faf35..e293427a 100644 --- a/src/http2.h +++ b/src/http2.h @@ -50,6 +50,10 @@ namespace http2 { { (uint8_t*)NAME, (uint8_t*)VALUE, \ (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); diff --git a/src/nghttp.cc b/src/nghttp.cc index d1cb18fb..9d09ec0e 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -965,8 +965,8 @@ int submit_request for(auto& kv : build_headers) { nva.push_back(http2::make_nv(kv.first, kv.second)); } - int rv = nghttp2_submit_request2(client->session, req->pri, - nva.data(), nva.size(), req->data_prd, req); + int rv = nghttp2_submit_request(client->session, req->pri, + nva.data(), nva.size(), req->data_prd, req); if(rv != 0) { std::cerr << "nghttp2_submit_request() returned error: " << nghttp2_strerror(rv) << std::endl; diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 046564bf..d1f9e0f1 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -575,8 +575,8 @@ int Http2Session::submit_request(Http2DownstreamConnection *dconn, { assert(state_ == CONNECTED); auto sd = util::make_unique(); - int rv = nghttp2_submit_request2(session_, pri, nva, nvlen, - data_prd, sd.get()); + int rv = nghttp2_submit_request(session_, pri, nva, nvlen, + data_prd, sd.get()); if(rv == 0) { dconn->attach_stream_data(sd.get()); streams_.insert(sd.release()); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index c96a600c..50e23a7d 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -878,16 +878,15 @@ int Http2Upstream::error_reply(Downstream *downstream, auto content_length = util::utos(html.size()); auto status_code_str = util::utos(status_code); - const char *nv[] = { - ":status", status_code_str.c_str(), - "content-type", "text/html; charset=UTF-8", - "server", get_config()->server_name, - "content-length", content_length.c_str(), - nullptr + auto nva = std::vector{ + MAKE_NV_LS(":status", status_code_str), + MAKE_NV_LS_LS("content-type", "text/html; charset=UTF-8"), + MAKE_NV_LS_CS("server", get_config()->server_name), + MAKE_NV_LS("content-length", content_length) }; - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), nv, - &data_prd); + rv = nghttp2_submit_response(session_, downstream->get_stream_id(), + nva.data(), nva.size(), &data_prd); if(rv < NGHTTP2_ERR_FATAL) { ULOG(FATAL, this) << "nghttp2_submit_response() failed: " << nghttp2_strerror(rv); @@ -992,8 +991,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) data_prd.read_callback = downstream_data_read_callback; int rv; - rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), - nva.data(), nva.size(), &data_prd); + rv = nghttp2_submit_response(session_, downstream->get_stream_id(), + nva.data(), nva.size(), &data_prd); if(rv != 0) { ULOG(FATAL, this) << "nghttp2_submit_response() failed"; return -1; diff --git a/tests/failmalloc_test.c b/tests/failmalloc_test.c index df750c72..9fd5a19a 100644 --- a/tests/failmalloc_test.c +++ b/tests/failmalloc_test.c @@ -114,9 +114,10 @@ static void run_nghttp2_session_send(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":host", "example.org", - ":scheme", "https", - NULL }; + nghttp2_nv nv[] = { + MAKE_NV(":host", "example.org"), + MAKE_NV(":scheme", "https") + }; nghttp2_data_provider data_prd; nghttp2_settings_entry iv[2]; my_user_data ud; @@ -136,12 +137,12 @@ static void run_nghttp2_session_send(void) if(rv != 0) { 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) { goto fail; } rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, - NGHTTP2_PRI_DEFAULT, nv, NULL); + NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL); if(rv != 0) { goto fail; } @@ -152,7 +153,7 @@ static void run_nghttp2_session_send(void) /* The HEADERS submitted by the previous nghttp2_submit_headers will have stream ID 3. Send HEADERS to that stream. */ rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, - NGHTTP2_PRI_DEFAULT, nv, NULL); + NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL); if(rv != 0) { goto fail; } @@ -175,7 +176,7 @@ static void run_nghttp2_session_send(void) } /* Sending against half-closed stream */ rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, - NGHTTP2_PRI_DEFAULT, nv, NULL); + NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL); if(rv != 0) { goto fail; } @@ -224,9 +225,10 @@ static void run_nghttp2_session_recv(void) uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - const char *nv[] = { ":authority", "example.org", - ":scheme", "https", - NULL }; + nghttp2_nv nv[] = { + MAKE_NV(":authority", "example.org"), + MAKE_NV(":scheme", "https") + }; nghttp2_settings_entry iv[2]; my_user_data ud; data_feed df; @@ -239,13 +241,13 @@ static void run_nghttp2_session_recv(void) ud.df = &df; nghttp2_failmalloc_pause(); + nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv)); nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST); nghttp2_session_server_new(&session, &callbacks, &ud); nghttp2_failmalloc_unpause(); /* HEADERS */ nghttp2_failmalloc_pause(); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM, 1, NGHTTP2_PRI_DEFAULT, nva, nvlen); 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; size_t buflen = 0; ssize_t framelen; - const char *nv[] = { ":host", "example.org", - ":scheme", "https", - NULL }; + nghttp2_nv nv[] = { + MAKE_NV(":host", "example.org"), + MAKE_NV(":scheme", "https") + }; int rv; nghttp2_nv *nva; ssize_t nvlen; @@ -334,7 +337,7 @@ static void run_nghttp2_frame_pack_headers(void) if(rv != 0) { goto inflate_init_fail; } - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv)); if(nvlen < 0) { goto nv_copy_fail; } diff --git a/tests/main.c b/tests/main.c index d7780326..743956e9 100644 --- a/tests/main.c +++ b/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_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", test_nghttp2_submit_request_with_data) || !CU_add_test(pSuite, "submit_request_without_data", test_nghttp2_submit_request_without_data) || - !CU_add_test(pSuite, "submit_request2_with_data", - test_nghttp2_submit_request2_with_data) || - !CU_add_test(pSuite, "submit_request2_without_data", - test_nghttp2_submit_request2_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_response_with_data", + test_nghttp2_submit_response_with_data) || + !CU_add_test(pSuite, "submit_response_without_data", + test_nghttp2_submit_response_without_data) || !CU_add_test(pSuite, "submit_headers_start_stream", test_nghttp2_submit_headers_start_stream) || !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) || !CU_add_test(pSuite, "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", test_nghttp2_frame_pack_headers) || !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) || !CU_add_test(pSuite, "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, "iv_check", test_nghttp2_iv_check) || !CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) || diff --git a/tests/nghttp2_frame_test.c b/tests/nghttp2_frame_test.c index e8ddb831..ad41deab 100644 --- a/tests/nghttp2_frame_test.c +++ b/tests/nghttp2_frame_test.c @@ -33,28 +33,29 @@ #include "nghttp2_helper.h" #include "nghttp2_test_helper.h" -static const char *headers[] = { - "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) +static nghttp2_nv make_nv(const char *name, const char *value) { - const char *headers1[] = { "path", "/", "host", "a", NULL }; - const char *headers2[] = { "", "/", "host", "a", NULL }; - const char *headers3[] = { "path", "/", "host\x01", "a", NULL }; - const char *headers4[] = { "PATH", "/", "host", NULL, NULL }; + nghttp2_nv nv; + nv.name = (uint8_t*)name; + nv.value = (uint8_t*)value; + nv.namelen = strlen(name); + nv.valuelen = strlen(value); + return nv; +} - CU_ASSERT(nghttp2_frame_nv_check_null(headers1)); - CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers2)); - CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers3)); - CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers4)); +#define HEADERS_LENGTH 7 + +static nghttp2_nv* headers(void) +{ + 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, @@ -79,7 +80,8 @@ void test_nghttp2_frame_pack_headers() nghttp2_hd_deflate_init(&deflater, 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_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS, 1000000007, @@ -138,19 +140,20 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void) nghttp2_nv *nva; ssize_t nvlen; size_t big_vallen = NGHTTP2_MAX_HD_VALUE_LENGTH; - char *big_hds[17]; - size_t big_hdslen = sizeof(big_hds)/sizeof(big_hds[0]) - 1; + nghttp2_nv big_hds[8]; + size_t big_hdslen = ARRLEN(big_hds); size_t i; - for(i = 0; i < big_hdslen; i += 2) { - big_hds[i] = (char*)"header"; - big_hds[i+1] = malloc(big_vallen+1); - memset(big_hds[i+1], '0'+i, big_vallen); - big_hds[i+1][big_vallen] = '\0'; + for(i = 0; i < big_hdslen; ++i) { + big_hds[i].name = (uint8_t*)"header"; + big_hds[i].value = malloc(big_vallen+1); + memset(big_hds[i].value, '0'+i, big_vallen); + 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_frame_headers_init(&frame, 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); free(buf); - for(i = 0; i < big_hdslen; i += 2) { - free(big_hds[i+1]); + for(i = 0; i < big_hdslen; ++i) { + free(big_hds[i].value); } 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_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, 1000000007, (1U << 31) - 1, nva, nvlen); 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))); } -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) { nghttp2_nv *nva; diff --git a/tests/nghttp2_frame_test.h b/tests/nghttp2_frame_test.h index 36ed15db..3ed76ff8 100644 --- a/tests/nghttp2_frame_test.h +++ b/tests/nghttp2_frame_test.h @@ -25,7 +25,6 @@ #ifndef 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_frame_too_large(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_window_update(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_iv_check(void); diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 180918da..1d957ff2 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -312,25 +312,14 @@ static nghttp2_settings_entry* dup_iv(const nghttp2_settings_entry *iv, return nghttp2_frame_iv_copy(iv, niv); } -static const char *empty_name_nv[] = { "Version", "HTTP/1.1", - "", "empty name", - NULL }; - -static const char *null_val_nv[] = { "Version", "HTTP/1.1", - "Foo", NULL, - NULL }; - void test_nghttp2_session_recv(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; scripted_data_feed df; my_user_data user_data; - const char *nv[] = { - "url", "/", NULL - }; - const char *empty_nv[] = { - NULL + const nghttp2_nv nv[] = { + MAKE_NV("url", "/") }; uint8_t *framedata = NULL; size_t framedatalen = 0; @@ -350,7 +339,7 @@ void test_nghttp2_session_recv(void) nghttp2_session_server_new(&session, &callbacks, &user_data); nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv)); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_PRI_DEFAULT, nva, nvlen); framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen, @@ -372,9 +361,8 @@ void test_nghttp2_session_recv(void) CU_ASSERT(1 == user_data.frame_recv_cb_called); /* Received HEADERS without header block, which is valid */ - nvlen = nghttp2_nv_array_from_cstr(&nva, empty_nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, - 5, NGHTTP2_PRI_DEFAULT, nva, nvlen); + 5, NGHTTP2_PRI_DEFAULT, NULL, 0); framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen, &frame.headers, &deflater); @@ -420,13 +408,10 @@ void test_nghttp2_session_recv_invalid_stream_id(void) nghttp2_session_callbacks callbacks; scripted_data_feed df; my_user_data user_data; - const char *nv[] = { NULL }; uint8_t *framedata = NULL; size_t framedatalen = 0; ssize_t framelen; nghttp2_frame frame; - nghttp2_nv *nva; - ssize_t nvlen; nghttp2_hd_context deflater; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -437,9 +422,9 @@ void test_nghttp2_session_recv_invalid_stream_id(void) user_data.invalid_frame_recv_cb_called = 0; nghttp2_session_server_new(&session, &callbacks, &user_data); nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 2, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen, &frame.headers, &deflater); @@ -462,8 +447,8 @@ void test_nghttp2_session_recv_invalid_frame(void) nghttp2_session_callbacks callbacks; scripted_data_feed df; my_user_data user_data; - const char *nv[] = { - "url", "/", NULL + const nghttp2_nv nv[] = { + MAKE_NV("url", "/") }; uint8_t *framedata = NULL; size_t framedatalen = 0; @@ -482,7 +467,7 @@ void test_nghttp2_session_recv_invalid_frame(void) user_data.frame_send_cb_called = 0; nghttp2_session_server_new(&session, &callbacks, &user_data); nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv)); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_PRI_DEFAULT, nva, nvlen); framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen, @@ -657,11 +642,11 @@ void test_nghttp2_session_continue(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv1[] = { - "url", "/", NULL + const nghttp2_nv nv1[] = { + MAKE_NV("url", "/") }; - const char *nv2[] = { - "user-agent", "nghttp2/1.0.0", NULL + const nghttp2_nv nv2[] = { + MAKE_NV("user-agent", "nghttp2/1.0.0") }; uint8_t *framedata = NULL; size_t framedatalen = 0; @@ -673,7 +658,6 @@ void test_nghttp2_session_continue(void) nghttp2_nv *nva; ssize_t nvlen; const nghttp2_frame *recv_frame; - nghttp2_nv nvcheck; nghttp2_frame_hd data_hd; nghttp2_hd_context deflater; @@ -688,7 +672,7 @@ void test_nghttp2_session_continue(void) nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST); /* Make 2 HEADERS frames */ - nvlen = nghttp2_nv_array_from_cstr(&nva, nv1); + nvlen = nghttp2_nv_array_copy(&nva, nv1, ARRLEN(nv1)); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_PRI_DEFAULT, nva, nvlen); framelen1 = nghttp2_frame_pack_headers(&framedata, &framedatalen, @@ -699,7 +683,7 @@ void test_nghttp2_session_continue(void) nghttp2_hd_end_headers(&deflater); memcpy(buffer, framedata, framelen1); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv2); + nvlen = nghttp2_nv_array_copy(&nva, nv2, ARRLEN(nv2)); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 3, NGHTTP2_PRI_DEFAULT, nva, nvlen); framelen2 = nghttp2_frame_pack_headers(&framedata, &framedatalen, @@ -719,11 +703,7 @@ void test_nghttp2_session_continue(void) CU_ASSERT(NGHTTP2_HEADERS == recv_frame->hd.type); CU_ASSERT(framelen1 - NGHTTP2_FRAME_HEAD_LENGTH == recv_frame->hd.length); CU_ASSERT(1 == recv_frame->headers.nvlen); - nvcheck.name = (uint8_t*)nv1[0]; - nvcheck.namelen = strlen(nv1[0]); - nvcheck.value = (uint8_t*)nv1[1]; - nvcheck.valuelen = strlen(nv1[1]); - CU_ASSERT(nghttp2_nv_equal(&nvcheck, recv_frame->headers.nva)); + CU_ASSERT(nghttp2_nv_equal(&nv1[0], recv_frame->headers.nva)); rv = nghttp2_session_continue(session); CU_ASSERT(rv == 0); @@ -737,11 +717,7 @@ void test_nghttp2_session_continue(void) CU_ASSERT(NGHTTP2_HEADERS == recv_frame->hd.type); CU_ASSERT(framelen2 - NGHTTP2_FRAME_HEAD_LENGTH == recv_frame->hd.length); CU_ASSERT(1 == recv_frame->headers.nvlen); - nvcheck.name = (uint8_t*)nv2[0]; - nvcheck.namelen = strlen(nv2[0]); - nvcheck.value = (uint8_t*)nv2[1]; - nvcheck.valuelen = strlen(nv2[1]); - CU_ASSERT(nghttp2_nv_equal(&nvcheck, recv_frame->headers.nva)); + CU_ASSERT(nghttp2_nv_equal(&nv2[0], recv_frame->headers.nva)); rv = nghttp2_session_continue(session); CU_ASSERT(rv == 0); @@ -773,12 +749,11 @@ void test_nghttp2_session_add_frame(void) nghttp2_session_callbacks callbacks; accumulator acc; my_user_data user_data; - const char *nv[] = { - "method", "GET", - "scheme", "https", - "url", "/", - "version", "HTTP/1.1", - NULL + const nghttp2_nv nv[] = { + MAKE_NV("method", "GET"), + MAKE_NV("scheme", "https"), + MAKE_NV("url", "/"), + MAKE_NV("version", "HTTP/1.1") }; nghttp2_frame *frame; nghttp2_headers_aux_data *aux_data = @@ -794,7 +769,7 @@ void test_nghttp2_session_add_frame(void) CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &user_data)); frame = malloc(sizeof(nghttp2_frame)); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv)); nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, -1, NGHTTP2_PRI_DEFAULT, nva, nvlen); @@ -816,12 +791,9 @@ void test_nghttp2_session_on_request_headers_received(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv[] = { NULL }; nghttp2_frame frame; nghttp2_stream *stream; int32_t stream_id = 1; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; @@ -830,10 +802,9 @@ void test_nghttp2_session_on_request_headers_received(void) user_data.invalid_frame_recv_cb_called = 0; nghttp2_session_server_new(&session, &callbacks, &user_data); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, - stream_id, 1 << 20, nva, nvlen); + stream_id, 1 << 20, NULL, 0); CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); CU_ASSERT(1 == user_data.frame_recv_cb_called); @@ -845,9 +816,8 @@ void test_nghttp2_session_on_request_headers_received(void) /* More than max concurrent streams leads REFUSED_STREAM */ session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, - 3, NGHTTP2_PRI_DEFAULT, nva, nvlen); + 3, NGHTTP2_PRI_DEFAULT, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); @@ -857,11 +827,10 @@ void test_nghttp2_session_on_request_headers_received(void) session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS; - /* Stream ID less than or equal to the previouly received SYN_STREAM - leads to connection error */ - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + /* Stream ID less than or equal to the previouly received request + HEADERS leads to connection error */ nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, - 3, NGHTTP2_PRI_DEFAULT, nva, nvlen); + 3, NGHTTP2_PRI_DEFAULT, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); @@ -877,11 +846,8 @@ void test_nghttp2_session_on_response_headers_received(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv[] = { NULL }; nghttp2_frame frame; nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; @@ -893,9 +859,8 @@ void test_nghttp2_session_on_response_headers_received(void) stream = nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); CU_ASSERT(0 == nghttp2_session_on_response_headers_received (session, &frame, stream)); @@ -911,11 +876,8 @@ void test_nghttp2_session_on_headers_received(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv[] = { NULL }; nghttp2_frame frame; nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; @@ -928,9 +890,8 @@ void test_nghttp2_session_on_headers_received(void) NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENED, NULL); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); CU_ASSERT(1 == user_data.frame_recv_cb_called); @@ -982,11 +943,8 @@ void test_nghttp2_session_on_push_response_headers_received(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv[] = { NULL }; nghttp2_frame frame; nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; nghttp2_outbound_item *item; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -999,9 +957,8 @@ void test_nghttp2_session_on_push_response_headers_received(void) stream = nghttp2_session_open_stream(session, 2, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_RESERVED, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 2, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); /* nghttp2_session_on_push_response_headers_received assumes stream's state is NGHTTP2_STREAM_RESERVED and session->server is 0. */ @@ -1177,12 +1134,9 @@ void test_nghttp2_session_on_push_promise_received(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv[] = { NULL }; nghttp2_frame frame; nghttp2_stream *stream, *promised_stream; nghttp2_outbound_item *item; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; @@ -1195,10 +1149,9 @@ void test_nghttp2_session_on_push_promise_received(void) stream = nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_PUSH_PROMISE, 1, 2, - nva, nvlen); + NULL, 0); CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); @@ -1290,11 +1243,10 @@ void test_nghttp2_session_on_push_promise_received(void) stream = nghttp2_session_open_stream(session, 2, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_RESERVED, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); /* Attempt to PUSH_PROMISE against reserved (remote) stream */ nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_PUSH_PROMISE, 2, 4, - nva, nvlen); + NULL, 0); user_data.frame_recv_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; @@ -1313,10 +1265,9 @@ void test_nghttp2_session_on_push_promise_received(void) session->local_settings[NGHTTP2_SETTINGS_ENABLE_PUSH] = 0; - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_PUSH_PROMISE, 1, 2, - nva, nvlen); + NULL, 0); user_data.frame_recv_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; @@ -1505,22 +1456,18 @@ void test_nghttp2_session_send_headers_start_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); nghttp2_stream *stream; nghttp2_headers_aux_data *aux_data = malloc(sizeof(nghttp2_headers_aux_data)); - nghttp2_nv *nva; - ssize_t nvlen; memset(aux_data, 0, sizeof(nghttp2_headers_aux_data)); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, -1, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, aux_data); CU_ASSERT(0 == nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); @@ -1533,11 +1480,8 @@ void test_nghttp2_session_send_headers_reply(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; @@ -1546,9 +1490,8 @@ void test_nghttp2_session_send_headers_reply(void) nghttp2_session_open_stream(session, 2, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 2, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); CU_ASSERT(0 == nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 2); @@ -1566,23 +1509,24 @@ void test_nghttp2_session_send_headers_header_comp_error(void) nghttp2_nv *nva; ssize_t nvlen; size_t vallen = NGHTTP2_MAX_HD_VALUE_LENGTH; - char *nv[17]; - size_t nnv = sizeof(nv)/sizeof(nv[0]) - 1; + nghttp2_nv nv[8]; + size_t nnv = ARRLEN(nv); size_t i; - for(i = 0; i < nnv; i += 2) { - nv[i] = (char*)"header"; - nv[i+1] = malloc(vallen+1); - memset(nv[i+1], '0'+i, vallen); - nv[i+1][vallen] = '\0'; + for(i = 0; i < nnv; ++i) { + nv[i].name = (uint8_t*)"header"; + nv[i].namelen = strlen((const char*)nv[i].name); + nv[i].value = malloc(vallen+1); + memset(nv[i].value, '0'+i, vallen); + nv[i].value[vallen] = '\0'; + nv[i].valuelen = vallen; } - nv[nnv] = NULL; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, (const char**)nv); + nvlen = nghttp2_nv_array_copy(&nva, nv, nnv); nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, -1, NGHTTP2_PRI_DEFAULT, nva, nvlen); @@ -1593,8 +1537,8 @@ void test_nghttp2_session_send_headers_header_comp_error(void) CU_ASSERT(session->goaway_flags & (NGHTTP2_GOAWAY_SEND | NGHTTP2_GOAWAY_FAIL_ON_SEND)); - for(i = 0; i < nnv; i += 2) { - free(nv[i+1]); + for(i = 0; i < nnv; ++i) { + free(nv[i].value); } nghttp2_session_del(session); } @@ -1603,11 +1547,8 @@ void test_nghttp2_session_send_headers_push_reply(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; @@ -1616,9 +1557,8 @@ void test_nghttp2_session_send_headers_push_reply(void) nghttp2_session_open_stream(session, 2, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_RESERVED, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 2, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); CU_ASSERT(0 == nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 2); @@ -1654,11 +1594,8 @@ void test_nghttp2_session_send_push_promise(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; nghttp2_settings_entry iv; my_user_data ud; @@ -1670,10 +1607,9 @@ void test_nghttp2_session_send_push_promise(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_push_promise_init(&frame->push_promise, NGHTTP2_FLAG_END_PUSH_PROMISE, 1, -1, - nva, nvlen); + NULL, 0); nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -1691,10 +1627,9 @@ void test_nghttp2_session_send_push_promise(void) free(frame); frame = malloc(sizeof(nghttp2_frame)); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_push_promise_init(&frame->push_promise, NGHTTP2_FLAG_END_PUSH_PROMISE, 1, -1, - nva, nvlen); + NULL, 0); nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); ud.frame_not_send_cb_called = 0; CU_ASSERT(0 == nghttp2_session_send(session)); @@ -1710,11 +1645,10 @@ void test_nghttp2_session_send_push_promise(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); frame = malloc(sizeof(nghttp2_frame)); nghttp2_frame_push_promise_init(&frame->push_promise, NGHTTP2_FLAG_END_PUSH_PROMISE, 1, -1, - nva, nvlen); + NULL, 0); nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -1841,7 +1775,6 @@ void test_nghttp2_session_reprioritize_stream(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - const char *nv[] = {NULL}; nghttp2_stream *stream; nghttp2_outbound_item *item; @@ -1858,13 +1791,13 @@ void test_nghttp2_session_reprioritize_stream(void) CU_ASSERT(0 == nghttp2_submit_push_promise(session, NGHTTP2_FLAG_END_PUSH_PROMISE, - 3, nv)); + 3, NULL, 0)); ud.block_count = 0; CU_ASSERT(0 == nghttp2_session_send(session)); /* Now PUSH_PROMISE is in aob */ - CU_ASSERT(0 == nghttp2_submit_response(session, 1, nv, NULL)); - CU_ASSERT(0 == nghttp2_submit_response(session, 3, nv, NULL)); + CU_ASSERT(0 == nghttp2_submit_response(session, 1, NULL, 0, NULL)); + CU_ASSERT(0 == nghttp2_submit_response(session, 3, NULL, 0, NULL)); nghttp2_session_reprioritize_stream(session, stream, 120); @@ -1888,74 +1821,13 @@ void test_nghttp2_session_reprioritize_stream(void) nghttp2_session_del(session); } -void test_nghttp2_submit_response(void) -{ - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - const char *nv[] = { "content-length", "1024", NULL }; - nghttp2_data_provider data_prd; - my_user_data ud; - nghttp2_outbound_item *item; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - - data_prd.read_callback = fixed_length_data_source_read_callback; - ud.data_source_length = 64*1024; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - nghttp2_session_open_stream(session, 2, NGHTTP2_FLAG_NONE, - NGHTTP2_PRI_DEFAULT, - NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(0 == nghttp2_submit_response(session, 2, nv, &data_prd)); - item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(nvnameeq("content-length", &OB_CTRL(item)->headers.nva[0])); - CU_ASSERT(0 == nghttp2_session_send(session)); - nghttp2_session_del(session); -} - -void test_nghttp2_submit_response_without_data(void) -{ - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - accumulator acc; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; - nghttp2_data_provider data_prd = {{-1}, NULL}; - nghttp2_outbound_item *item; - my_user_data ud; - nghttp2_frame frame; - nghttp2_hd_context inflater; - - acc.length = 0; - ud.acc = &acc; - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); - nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_RESPONSE); - nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_END_STREAM, - NGHTTP2_PRI_DEFAULT, - NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, nv, &data_prd)); - item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); - CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM); - - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame_with_nv_block(&frame, NGHTTP2_HEADERS, - &inflater, - acc.buf, acc.length)); - CU_ASSERT(nvnameeq(":version", &frame.headers.nva[0])); - nghttp2_frame_headers_free(&frame.headers); - nghttp2_hd_end_headers(&inflater); - - nghttp2_hd_inflate_free(&inflater); - nghttp2_session_del(session); -} - void test_nghttp2_submit_request_with_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + nghttp2_nv nva[] = { + MAKE_NV(":version", "HTTP/1.1") + }; nghttp2_data_provider data_prd; my_user_data ud; nghttp2_outbound_item *item; @@ -1966,8 +1838,8 @@ void test_nghttp2_submit_request_with_data(void) data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64*1024 - 1; CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - CU_ASSERT(0 == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv, - &data_prd, NULL)); + CU_ASSERT(0 == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, + nva, ARRLEN(nva), &data_prd, NULL)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -1981,7 +1853,9 @@ void test_nghttp2_submit_request_without_data(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + nghttp2_nv nva[] = { + MAKE_NV(":version", "HTTP/1.1") + }; nghttp2_data_provider data_prd = {{-1}, NULL}; nghttp2_outbound_item *item; my_user_data ud; @@ -1994,8 +1868,8 @@ void test_nghttp2_submit_request_without_data(void) callbacks.send_callback = accumulator_send_callback; CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST); - CU_ASSERT(0 == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv, - &data_prd, NULL)); + CU_ASSERT(0 == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, + nva, ARRLEN(nva), &data_prd, NULL)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM); @@ -2012,72 +1886,13 @@ void test_nghttp2_submit_request_without_data(void) nghttp2_session_del(session); } -void test_nghttp2_submit_request2_with_data(void) +void test_nghttp2_submit_response_with_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_nv nva[] = {MAKE_NV(":version", "HTTP/1.1")}; - nghttp2_data_provider data_prd; - my_user_data ud; - nghttp2_outbound_item *item; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - - data_prd.read_callback = fixed_length_data_source_read_callback; - ud.data_source_length = 64*1024 - 1; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - CU_ASSERT(0 == nghttp2_submit_request2(session, NGHTTP2_PRI_DEFAULT, - nva, ARRLEN(nva), &data_prd, NULL)); - item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); - - nghttp2_session_del(session); -} - -void test_nghttp2_submit_request2_without_data(void) -{ - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - accumulator acc; - nghttp2_nv nva[] = {MAKE_NV(":version", "HTTP/1.1")}; - nghttp2_data_provider data_prd = {{-1}, NULL}; - nghttp2_outbound_item *item; - my_user_data ud; - nghttp2_frame frame; - nghttp2_hd_context inflater; - - acc.length = 0; - ud.acc = &acc; - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST); - CU_ASSERT(0 == nghttp2_submit_request2(session, NGHTTP2_PRI_DEFAULT, - nva, ARRLEN(nva), &data_prd, NULL)); - item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); - CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM); - - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame_with_nv_block(&frame, NGHTTP2_HEADERS, - &inflater, - acc.buf, acc.length)); - CU_ASSERT(nvnameeq(":version", &frame.headers.nva[0])); - nghttp2_frame_headers_free(&frame.headers); - nghttp2_hd_end_headers(&inflater); - - nghttp2_hd_inflate_free(&inflater); - nghttp2_session_del(session); -} - -void test_nghttp2_submit_response2_with_data(void) -{ - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_nv nva[] = {MAKE_NV(":version", "HTTP/1.1")}; + nghttp2_nv nva[] = { + MAKE_NV(":version", "HTTP/1.1") + }; nghttp2_data_provider data_prd; my_user_data ud; nghttp2_outbound_item *item; @@ -2091,8 +1906,8 @@ void test_nghttp2_submit_response2_with_data(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_END_STREAM, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(0 == nghttp2_submit_response2(session, 1, nva, ARRLEN(nva), - &data_prd)); + CU_ASSERT(0 == nghttp2_submit_response(session, 1, nva, ARRLEN(nva), + &data_prd)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -2101,12 +1916,14 @@ void test_nghttp2_submit_response2_with_data(void) nghttp2_session_del(session); } -void test_nghttp2_submit_response2_without_data(void) +void test_nghttp2_submit_response_without_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_nv nva[] = {MAKE_NV(":version", "HTTP/1.1")}; + nghttp2_nv nva[] = { + MAKE_NV(":version", "HTTP/1.1") + }; nghttp2_data_provider data_prd = {{-1}, NULL}; nghttp2_outbound_item *item; my_user_data ud; @@ -2122,8 +1939,8 @@ void test_nghttp2_submit_response2_without_data(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_END_STREAM, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(0 == nghttp2_submit_response2(session, 1, nva, ARRLEN(nva), - &data_prd)); + CU_ASSERT(0 == nghttp2_submit_response(session, 1, nva, ARRLEN(nva), + &data_prd)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM); @@ -2144,7 +1961,9 @@ void test_nghttp2_submit_headers_start_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + const nghttp2_nv nv[] = { + MAKE_NV(":version", "HTTP/1.1") + }; nghttp2_outbound_item *item; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -2152,7 +1971,7 @@ void test_nghttp2_submit_headers_start_stream(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, NGHTTP2_PRI_DEFAULT, - nv, NULL)); + nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM) == @@ -2166,7 +1985,9 @@ void test_nghttp2_submit_headers_reply(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + const nghttp2_nv nv[] = { + MAKE_NV(":version", "HTTP/1.1") + }; my_user_data ud; nghttp2_outbound_item *item; nghttp2_stream *stream; @@ -2179,7 +2000,7 @@ void test_nghttp2_submit_headers_reply(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NGHTTP2_PRI_DEFAULT, - nv, NULL)); + nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == @@ -2199,7 +2020,7 @@ void test_nghttp2_submit_headers_reply(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NGHTTP2_PRI_DEFAULT, - nv, NULL)); + nv, ARRLEN(nv), NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); CU_ASSERT(1 == ud.frame_send_cb_called); CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); @@ -2212,7 +2033,9 @@ void test_nghttp2_submit_headers_push_reply(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + const nghttp2_nv nv[] = { + MAKE_NV(":version", "HTTP/1.1") + }; my_user_data ud; nghttp2_stream *stream; int foo; @@ -2228,7 +2051,7 @@ void test_nghttp2_submit_headers_push_reply(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_PRI_DEFAULT, - nv, &foo)); + nv, ARRLEN(nv), &foo)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; @@ -2249,7 +2072,7 @@ void test_nghttp2_submit_headers_push_reply(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_PRI_DEFAULT, - nv, NULL)); + nv, ARRLEN(nv), NULL)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; @@ -2263,7 +2086,9 @@ void test_nghttp2_submit_headers(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + const nghttp2_nv nv[] = { + MAKE_NV(":version", "HTTP/1.1") + }; my_user_data ud; nghttp2_outbound_item *item; nghttp2_stream *stream; @@ -2282,7 +2107,7 @@ void test_nghttp2_submit_headers(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NGHTTP2_PRI_DEFAULT, - nv, NULL)); + nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == @@ -2302,7 +2127,7 @@ void test_nghttp2_submit_headers(void) CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NGHTTP2_PRI_DEFAULT, - nv, NULL)); + nv, ARRLEN(nv), NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); CU_ASSERT(1 == ud.frame_send_cb_called); CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); @@ -2514,7 +2339,9 @@ void test_nghttp2_submit_push_promise(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { ":version", "HTTP/1.1", NULL }; + const nghttp2_nv nv[] = { + MAKE_NV(":version", "HTTP/1.1") + }; my_user_data ud; nghttp2_stream *stream; @@ -2526,9 +2353,8 @@ void test_nghttp2_submit_push_promise(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(0 == nghttp2_submit_push_promise(session, - NGHTTP2_FLAG_NONE, - 1, nv)); + CU_ASSERT(0 == nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, + nv, ARRLEN(nv))); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; @@ -2689,6 +2515,10 @@ void test_nghttp2_submit_invalid_nv(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; + nghttp2_nv empty_name_nv[] = { + MAKE_NV("Version", "HTTP/1.1"), + MAKE_NV("", "empty name") + }; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -2697,27 +2527,26 @@ void test_nghttp2_submit_invalid_nv(void) /* nghttp2_submit_request */ CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, - empty_name_nv, NULL, NULL)); - - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, - null_val_nv, NULL, NULL)); + empty_name_nv, ARRLEN(empty_name_nv), + NULL, NULL)); /* nghttp2_submit_response */ CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_response(session, 2, empty_name_nv, NULL)); - - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_response(session, 2, null_val_nv, NULL)); + nghttp2_submit_response(session, 2, + empty_name_nv, ARRLEN(empty_name_nv), + NULL)); /* nghttp2_submit_headers */ CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, - NGHTTP2_PRI_DEFAULT, empty_name_nv, NULL)); + NGHTTP2_PRI_DEFAULT, + empty_name_nv, ARRLEN(empty_name_nv), + NULL)); + /* nghttp2_submit_push_promise */ CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, - NGHTTP2_PRI_DEFAULT, null_val_nv, NULL)); + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 2, + empty_name_nv, ARRLEN(empty_name_nv))); nghttp2_session_del(session); } @@ -2774,7 +2603,6 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; @@ -2786,7 +2614,7 @@ void test_nghttp2_session_get_next_ob_item(void) CU_ASSERT(NGHTTP2_PING == OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); - nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv, NULL, NULL); + nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, NULL, NULL); CU_ASSERT(NGHTTP2_PING == OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); @@ -2799,12 +2627,12 @@ void test_nghttp2_session_get_next_ob_item(void) NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nghttp2_submit_request(session, 0, nv, NULL, NULL); + nghttp2_submit_request(session, 0, NULL, 0, NULL, NULL); CU_ASSERT(NGHTTP2_HEADERS == OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); CU_ASSERT(0 == nghttp2_session_send(session)); - nghttp2_submit_request(session, 0, nv, NULL, NULL); + nghttp2_submit_request(session, 0, NULL, 0, NULL, NULL); CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 3; @@ -2819,7 +2647,6 @@ void test_nghttp2_session_pop_next_ob_item(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; nghttp2_outbound_item *item; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; @@ -2829,7 +2656,7 @@ void test_nghttp2_session_pop_next_ob_item(void) CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); - nghttp2_submit_request(session, 1, nv, NULL, NULL); + nghttp2_submit_request(session, 1, NULL, 0, NULL, NULL); item = nghttp2_session_pop_next_ob_item(session); CU_ASSERT(NGHTTP2_PING == OB_CTRL_TYPE(item)); @@ -2851,8 +2678,8 @@ void test_nghttp2_session_pop_next_ob_item(void) nghttp2_session_open_stream(session, 4, NGHTTP2_FLAG_NONE, 3, NGHTTP2_STREAM_OPENING, NULL); - nghttp2_submit_request(session, 0, nv, NULL, NULL); - nghttp2_submit_response(session, 1, nv, NULL); + nghttp2_submit_request(session, 0, NULL, 0, NULL, NULL); + nghttp2_submit_response(session, 1, NULL, 0, NULL); item = nghttp2_session_pop_next_ob_item(session); CU_ASSERT(NGHTTP2_HEADERS == OB_CTRL_TYPE(item)); @@ -2878,7 +2705,8 @@ void test_nghttp2_session_pop_next_ob_item(void) NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_RESERVED, NULL); CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, - 2, NGHTTP2_PRI_DEFAULT, nv, NULL)); + 2, NGHTTP2_PRI_DEFAULT, NULL, 0, + NULL)); CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); CU_ASSERT(1 == nghttp2_pq_size(&session->ob_ss_pq)); nghttp2_session_del(session); @@ -2888,7 +2716,6 @@ void test_nghttp2_session_reply_fail(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; nghttp2_data_provider data_prd; my_user_data ud; @@ -2901,7 +2728,7 @@ void test_nghttp2_session_reply_fail(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, nv, &data_prd)); + CU_ASSERT(0 == nghttp2_submit_response(session, 1, NULL, 0, &data_prd)); CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -2911,19 +2738,15 @@ void test_nghttp2_session_max_concurrent_streams(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_frame frame; - const char *nv[] = { NULL }; nghttp2_outbound_item *item; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENED, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 3, - NGHTTP2_PRI_DEFAULT, nva, nvlen); + NGHTTP2_PRI_DEFAULT, NULL, 0); session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); @@ -2971,7 +2794,6 @@ void test_nghttp2_session_stop_data_with_rst_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; my_user_data ud; nghttp2_data_provider data_prd; nghttp2_frame frame; @@ -2988,7 +2810,7 @@ void test_nghttp2_session_stop_data_with_rst_stream(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nghttp2_submit_response(session, 1, nv, &data_prd); + nghttp2_submit_response(session, 1, NULL, 0, &data_prd); ud.block_count = 2; /* Sends SYN_REPLY + DATA[0] */ @@ -3018,7 +2840,6 @@ void test_nghttp2_session_defer_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; my_user_data ud; nghttp2_data_provider data_prd; nghttp2_outbound_item *item; @@ -3035,7 +2856,7 @@ void test_nghttp2_session_defer_data(void) nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nghttp2_submit_response(session, 1, nv, &data_prd); + nghttp2_submit_response(session, 1, NULL, 0, &data_prd); ud.block_count = 1; /* Sends HEADERS reply */ @@ -3086,7 +2907,6 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; my_user_data ud; nghttp2_data_provider data_prd; nghttp2_frame frame; @@ -3112,7 +2932,8 @@ void test_nghttp2_session_flow_control(void) session->remote_window_size = 64*1024; session->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE] = 64*1024; - nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv, &data_prd, NULL); + nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, + &data_prd, NULL); /* Sends 64KiB - 1 data */ CU_ASSERT(0 == nghttp2_session_send(session)); @@ -3202,7 +3023,6 @@ void test_nghttp2_session_flow_control_disable_remote(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; my_user_data ud; nghttp2_data_provider data_prd; nghttp2_frame frame; @@ -3219,7 +3039,8 @@ void test_nghttp2_session_flow_control_disable_remote(void) /* Initial window size is 64KiB */ nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv, &data_prd, NULL); + nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, + &data_prd, NULL); /* Sends 64KiB data */ CU_ASSERT(0 == nghttp2_session_send(session)); @@ -3343,7 +3164,6 @@ void test_nghttp2_session_data_read_temporal_failure(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; my_user_data ud; nghttp2_data_provider data_prd; nghttp2_frame frame; @@ -3360,7 +3180,7 @@ void test_nghttp2_session_data_read_temporal_failure(void) /* Initial window size is 64KiB - 1 */ nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, 3, nv, &data_prd, NULL); + nghttp2_submit_request(session, 3, NULL, 0, &data_prd, NULL); /* Sends NGHTTP2_INITIAL_WINDOW_SIZE data, assuming, it is equal to or smaller than NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE */ @@ -3392,7 +3212,7 @@ void test_nghttp2_session_data_read_temporal_failure(void) CU_ASSERT(NGHTTP2_RST_STREAM == ud.sent_frame_type); data_prd.read_callback = fail_data_source_read_callback; - nghttp2_submit_request(session, 3, nv, &data_prd, NULL); + nghttp2_submit_request(session, 3, NULL, 0, &data_prd, NULL); /* Sending data will fail (hard fail) and session tear down */ CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); @@ -3404,20 +3224,16 @@ void test_nghttp2_session_on_request_recv_callback(void) nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data user_data; - const char *nv[] = { NULL }; nghttp2_frame frame; nghttp2_stream *stream; - nghttp2_nv *nva; - ssize_t nvlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_request_recv_callback = on_request_recv_callback; user_data.stream_id = 0; nghttp2_session_server_new(&session, &callbacks, &user_data); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, - 1, NGHTTP2_PRI_DEFAULT, nva, nvlen); + 1, NGHTTP2_PRI_DEFAULT, NULL, 0); CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); CU_ASSERT(0 == user_data.stream_id); @@ -3434,9 +3250,8 @@ void test_nghttp2_session_on_request_recv_callback(void) stream = nghttp2_session_open_stream(session, 5, NGHTTP2_FLAG_NONE, NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENING, NULL); - nvlen = nghttp2_nv_array_from_cstr(&nva, nv); nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, - 5, NGHTTP2_PRI_DEFAULT, nva, nvlen); + 5, NGHTTP2_PRI_DEFAULT, NULL, 0); CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); CU_ASSERT(0 == user_data.stream_id); @@ -3477,7 +3292,6 @@ void test_nghttp2_session_on_ctrl_not_send(void) nghttp2_session_callbacks callbacks; my_user_data user_data; nghttp2_stream *stream; - const char *nv[] = { NULL }; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_not_send_callback = on_frame_not_send_callback; @@ -3495,7 +3309,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) /* Send bogus stream ID */ CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 3, - NGHTTP2_PRI_DEFAULT, nv, NULL)); + NGHTTP2_PRI_DEFAULT, NULL, 0, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); CU_ASSERT(1 == user_data.frame_not_send_cb_called); CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); @@ -3506,7 +3320,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) stream->shut_flags |= NGHTTP2_SHUT_WR; CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NGHTTP2_PRI_DEFAULT, nv, NULL)); + NGHTTP2_PRI_DEFAULT, NULL, 0, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); CU_ASSERT(1 == user_data.frame_not_send_cb_called); CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); @@ -3517,7 +3331,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) /* Queue RST_STREAM */ CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NGHTTP2_PRI_DEFAULT, nv, NULL)); + NGHTTP2_PRI_DEFAULT, NULL, 0, NULL)); CU_ASSERT(0 == nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_INTERNAL_ERROR)); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -3534,7 +3348,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) /* Queue RST_STREAM */ CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 3, - NGHTTP2_PRI_DEFAULT, nv, NULL)); + NGHTTP2_PRI_DEFAULT, NULL, 0, NULL)); CU_ASSERT(0 == nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 3, NGHTTP2_INTERNAL_ERROR)); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -3550,7 +3364,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) /* Maximum Stream ID is reached */ session->next_stream_id = (1u << 31)+1; CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NGHTTP2_PRI_DEFAULT, nv, NULL)); + NGHTTP2_PRI_DEFAULT, NULL, 0, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); CU_ASSERT(1 == user_data.frame_not_send_cb_called); CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); @@ -3565,7 +3379,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, NGHTTP2_NO_ERROR, NULL, 0)); CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NGHTTP2_PRI_DEFAULT, nv, NULL)); + NGHTTP2_PRI_DEFAULT, NULL, 0, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); CU_ASSERT(1 == user_data.frame_not_send_cb_called); CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); @@ -3709,7 +3523,6 @@ void test_nghttp2_session_data_backoff_by_high_pri_frame(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - const char *nv[] = { NULL }; my_user_data ud; nghttp2_data_provider data_prd; nghttp2_stream *stream; @@ -3723,7 +3536,8 @@ void test_nghttp2_session_data_backoff_by_high_pri_frame(void) ud.data_source_length = 16*1024; nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv, &data_prd, NULL); + nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, + &data_prd, NULL); ud.block_count = 2; /* Sends SYN_STREAM + DATA[0] */ diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h index ec4a11c7..d285f8dc 100644 --- a/tests/nghttp2_session_test.h +++ b/tests/nghttp2_session_test.h @@ -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_upgrade(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_without_data(void); -void test_nghttp2_submit_request2_with_data(void); -void test_nghttp2_submit_request2_without_data(void); -void test_nghttp2_submit_response2_with_data(void); -void test_nghttp2_submit_response2_without_data(void); +void test_nghttp2_submit_response_with_data(void); +void test_nghttp2_submit_response_without_data(void); void test_nghttp2_submit_headers_start_stream(void); void test_nghttp2_submit_headers_reply(void); void test_nghttp2_submit_headers_push_reply(void);