Lower-case names in name/value pairs in spdylay_submit_{request, response}
This commit is contained in:
parent
e7e2c69526
commit
85ec883d11
|
@ -394,9 +394,10 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session,
|
||||||
int32_t stream_id);
|
int32_t stream_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Submits SYN_STREAM frame. |pri| is priority of this request and it
|
* Submits SYN_STREAM frame and optionally one or more DATA
|
||||||
* must be in the range of [0, 3]. 0 means the higest priority. |nv|
|
* frames. |pri| is priority of this request and it must be in the
|
||||||
* must include following name/value pairs:
|
* range of [0, 3]. 0 means the higest priority. |nv| must include
|
||||||
|
* following name/value pairs:
|
||||||
*
|
*
|
||||||
* "method": HTTP method (e.g., "GET" or "POST")
|
* "method": HTTP method (e.g., "GET" or "POST")
|
||||||
* "scheme": URI scheme (e.g., "https")
|
* "scheme": URI scheme (e.g., "https")
|
||||||
|
@ -405,7 +406,8 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session,
|
||||||
*
|
*
|
||||||
* "host" name/value pair is also required by some hosts.
|
* "host" name/value pair is also required by some hosts.
|
||||||
*
|
*
|
||||||
* This function creates copies of all name/value pairs in |nv|.
|
* This function creates copies of all name/value pairs in |nv|. It
|
||||||
|
* also lower-cases all names in |nv|.
|
||||||
*
|
*
|
||||||
* If |data_prd| is not NULL, it provides data which will be sent in
|
* If |data_prd| is not NULL, it provides data which will be sent in
|
||||||
* subsequent DATA frames. In this case, "POST" must be specified with
|
* subsequent DATA frames. In this case, "POST" must be specified with
|
||||||
|
@ -426,14 +428,17 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri,
|
||||||
void *stream_user_data);
|
void *stream_user_data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Submits SYN_REPLY frame against stream |stream_id|. |nv| must
|
* Submits SYN_REPLY frame and optionally one or more DATA frames
|
||||||
* include following name/value pairs:
|
* against stream |stream_id|. |nv| must include following name/value
|
||||||
|
* pairs:
|
||||||
*
|
*
|
||||||
* "status": HTTP status code (e.g., "200" or "200 OK")
|
* "status": HTTP status code (e.g., "200" or "200 OK")
|
||||||
* "version": HTTP response version (e.g., "HTTP/1.1")
|
* "version": HTTP response version (e.g., "HTTP/1.1")
|
||||||
*
|
*
|
||||||
* This function creates copies of all name/value pairs in |nv|. If
|
* This function creates copies of all name/value pairs in |nv|. It
|
||||||
* |data_prd| is not NULL, it provides data which will be sent in
|
* also lower-cases all names in |nv|.
|
||||||
|
*
|
||||||
|
* If |data_prd| is not NULL, it provides data which will be sent in
|
||||||
* subsequent DATA frames. If |data_prd| is NULL, SYN_REPLY will have
|
* subsequent DATA frames. If |data_prd| is NULL, SYN_REPLY will have
|
||||||
* FLAG_FIN.
|
* FLAG_FIN.
|
||||||
*
|
*
|
||||||
|
|
|
@ -315,6 +315,18 @@ void spdylay_frame_nv_sort(char **nv)
|
||||||
qsort(nv, n/2, 2*sizeof(char*), spdylay_string_compar);
|
qsort(nv, n/2, 2*sizeof(char*), spdylay_string_compar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void spdylay_frame_nv_downcase(char **nv)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
for(i = 0; nv[i]; i += 2) {
|
||||||
|
for(j = 0; nv[i][j] != '\0'; ++j) {
|
||||||
|
if('A' <= nv[i][j] && nv[i][j] <= 'Z') {
|
||||||
|
nv[i][j] += 'a'-'A';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame, uint8_t flags,
|
void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame, uint8_t flags,
|
||||||
int32_t stream_id, int32_t assoc_stream_id,
|
int32_t stream_id, int32_t assoc_stream_id,
|
||||||
uint8_t pri, char **nv)
|
uint8_t pri, char **nv)
|
||||||
|
|
|
@ -293,6 +293,11 @@ char** spdylay_frame_nv_copy(const char **nv);
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_nv_sort(char **nv);
|
void spdylay_frame_nv_sort(char **nv);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Makes names in |nv| lower cased.
|
||||||
|
*/
|
||||||
|
void spdylay_frame_nv_downcase(char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Makes copy of |iv| and return the copy. The |niv| is the number of
|
* Makes copy of |iv| and return the copy. The |niv| is the number of
|
||||||
* entries in |iv|. This function returns the pointer to the copy if
|
* entries in |iv|. This function returns the pointer to the copy if
|
||||||
|
|
|
@ -71,6 +71,7 @@ int spdylay_submit_response(spdylay_session *session,
|
||||||
free(data_prd_copy);
|
free(data_prd_copy);
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return SPDYLAY_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
|
spdylay_frame_nv_downcase(nv_copy);
|
||||||
spdylay_frame_nv_sort(nv_copy);
|
spdylay_frame_nv_sort(nv_copy);
|
||||||
if(data_prd == NULL) {
|
if(data_prd == NULL) {
|
||||||
flags |= SPDYLAY_FLAG_FIN;
|
flags |= SPDYLAY_FLAG_FIN;
|
||||||
|
@ -151,6 +152,7 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri,
|
||||||
free(data_prd_copy);
|
free(data_prd_copy);
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return SPDYLAY_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
|
spdylay_frame_nv_downcase(nv_copy);
|
||||||
spdylay_frame_nv_sort(nv_copy);
|
spdylay_frame_nv_sort(nv_copy);
|
||||||
if(data_prd == NULL) {
|
if(data_prd == NULL) {
|
||||||
flags |= SPDYLAY_FLAG_FIN;
|
flags |= SPDYLAY_FLAG_FIN;
|
||||||
|
|
|
@ -132,6 +132,8 @@ int main(int argc, char* argv[])
|
||||||
!CU_add_test(pSuite, "frame_pack_settings",
|
!CU_add_test(pSuite, "frame_pack_settings",
|
||||||
test_spdylay_frame_pack_settings) ||
|
test_spdylay_frame_pack_settings) ||
|
||||||
!CU_add_test(pSuite, "frame_nv_sort", test_spdylay_frame_nv_sort) ||
|
!CU_add_test(pSuite, "frame_nv_sort", test_spdylay_frame_nv_sort) ||
|
||||||
|
!CU_add_test(pSuite, "frame_nv_downcase",
|
||||||
|
test_spdylay_frame_nv_downcase) ||
|
||||||
!CU_add_test(pSuite, "stream_add_pushed_stream",
|
!CU_add_test(pSuite, "stream_add_pushed_stream",
|
||||||
test_spdylay_stream_add_pushed_stream)) {
|
test_spdylay_stream_add_pushed_stream)) {
|
||||||
CU_cleanup_registry();
|
CU_cleanup_registry();
|
||||||
|
|
|
@ -230,3 +230,20 @@ void test_spdylay_frame_nv_sort()
|
||||||
CU_ASSERT(strcmp("version", nv[4]) == 0);
|
CU_ASSERT(strcmp("version", nv[4]) == 0);
|
||||||
CU_ASSERT(strcmp("HTTP/1.1", nv[5]) == 0);
|
CU_ASSERT(strcmp("HTTP/1.1", nv[5]) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_spdylay_frame_nv_downcase()
|
||||||
|
{
|
||||||
|
const char *nv_src[] = {
|
||||||
|
"VERSION", "HTTP/1.1",
|
||||||
|
"Content-Length", "1000000007",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
char **nv;
|
||||||
|
nv = spdylay_frame_nv_copy(nv_src);
|
||||||
|
spdylay_frame_nv_downcase(nv);
|
||||||
|
CU_ASSERT(0 == strcmp("version", nv[0]));
|
||||||
|
CU_ASSERT(0 == strcmp("HTTP/1.1", nv[1]));
|
||||||
|
CU_ASSERT(0 == strcmp("content-length", nv[2]));
|
||||||
|
CU_ASSERT(0 == strcmp("1000000007", nv[3]));
|
||||||
|
spdylay_frame_nv_del(nv);
|
||||||
|
}
|
||||||
|
|
|
@ -33,5 +33,6 @@ void test_spdylay_frame_pack_goaway();
|
||||||
void test_spdylay_frame_pack_headers();
|
void test_spdylay_frame_pack_headers();
|
||||||
void test_spdylay_frame_pack_settings();
|
void test_spdylay_frame_pack_settings();
|
||||||
void test_spdylay_frame_nv_sort();
|
void test_spdylay_frame_nv_sort();
|
||||||
|
void test_spdylay_frame_nv_downcase();
|
||||||
|
|
||||||
#endif /* SPDYLAY_FRAME_TEST_H */
|
#endif /* SPDYLAY_FRAME_TEST_H */
|
||||||
|
|
|
@ -527,10 +527,11 @@ void test_spdylay_submit_response()
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
const char *nv[] = { NULL };
|
const char *nv[] = { "Content-Length", "1024", NULL };
|
||||||
int32_t stream_id = 2;
|
int32_t stream_id = 2;
|
||||||
spdylay_data_provider data_prd;
|
spdylay_data_provider data_prd;
|
||||||
my_user_data ud;
|
my_user_data ud;
|
||||||
|
spdylay_outbound_item *item;
|
||||||
|
|
||||||
data_prd.read_callback = fixed_length_data_source_read_callback;
|
data_prd.read_callback = fixed_length_data_source_read_callback;
|
||||||
ud.data_source_length = 64*1024;
|
ud.data_source_length = 64*1024;
|
||||||
|
@ -538,6 +539,8 @@ void test_spdylay_submit_response()
|
||||||
spdylay_session_open_stream(session, stream_id, SPDYLAY_FLAG_NONE, 3,
|
spdylay_session_open_stream(session, stream_id, SPDYLAY_FLAG_NONE, 3,
|
||||||
SPDYLAY_STREAM_OPENING, NULL);
|
SPDYLAY_STREAM_OPENING, NULL);
|
||||||
CU_ASSERT(0 == spdylay_submit_response(session, stream_id, nv, &data_prd));
|
CU_ASSERT(0 == spdylay_submit_response(session, stream_id, nv, &data_prd));
|
||||||
|
item = spdylay_session_get_next_ob_item(session);
|
||||||
|
CU_ASSERT(0 == strcmp("content-length", item->frame->syn_reply.nv[0]));
|
||||||
CU_ASSERT(0 == spdylay_session_send(session));
|
CU_ASSERT(0 == spdylay_session_send(session));
|
||||||
spdylay_session_del(session);
|
spdylay_session_del(session);
|
||||||
}
|
}
|
||||||
|
@ -551,14 +554,17 @@ void test_spdylay_submit_request_with_data()
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
const char *nv[] = { NULL };
|
const char *nv[] = { "Version", "HTTP/1.1", NULL };
|
||||||
spdylay_data_provider data_prd;
|
spdylay_data_provider data_prd;
|
||||||
my_user_data ud;
|
my_user_data ud;
|
||||||
|
spdylay_outbound_item *item;
|
||||||
|
|
||||||
data_prd.read_callback = fixed_length_data_source_read_callback;
|
data_prd.read_callback = fixed_length_data_source_read_callback;
|
||||||
ud.data_source_length = 64*1024;
|
ud.data_source_length = 64*1024;
|
||||||
CU_ASSERT(0 == spdylay_session_client_new(&session, &callbacks, &ud));
|
CU_ASSERT(0 == spdylay_session_client_new(&session, &callbacks, &ud));
|
||||||
CU_ASSERT(0 == spdylay_submit_request(session, 3, nv, &data_prd, NULL));
|
CU_ASSERT(0 == spdylay_submit_request(session, 3, nv, &data_prd, NULL));
|
||||||
|
item = spdylay_session_get_next_ob_item(session);
|
||||||
|
CU_ASSERT(0 == strcmp("version", item->frame->syn_stream.nv[0]));
|
||||||
CU_ASSERT(0 == spdylay_session_send(session));
|
CU_ASSERT(0 == spdylay_session_send(session));
|
||||||
CU_ASSERT(0 == ud.data_source_length);
|
CU_ASSERT(0 == ud.data_source_length);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue