Remove nghttp2_on_request_recv_callback
It is easy enough to check the end of incoming data by evaluating frame->hd.flags & NGHTTP2_FLAG_END_STREAM in on_frame_recv_callback
This commit is contained in:
parent
03a94ecca7
commit
ab684a9f30
|
@ -899,6 +899,10 @@ typedef ssize_t (*nghttp2_recv_callback)
|
||||||
* check that stream is still alive using its own stream management or
|
* check that stream is still alive using its own stream management or
|
||||||
* :func:`nghttp2_session_get_stream_user_data()`.
|
* :func:`nghttp2_session_get_stream_user_data()`.
|
||||||
*
|
*
|
||||||
|
* Only HEADERS and DATA frame can signal the end of incoming data. If
|
||||||
|
* ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the
|
||||||
|
* |frame| is the last frame from the remote peer in this stream.
|
||||||
|
*
|
||||||
* The implementation of this function must return 0 if it
|
* The implementation of this function must return 0 if it
|
||||||
* succeeds. If nonzero value is returned, it is treated as fatal
|
* succeeds. If nonzero value is returned, it is treated as fatal
|
||||||
* error and `nghttp2_session_recv()` and `nghttp2_session_mem_recv()`
|
* error and `nghttp2_session_recv()` and `nghttp2_session_mem_recv()`
|
||||||
|
@ -1035,24 +1039,6 @@ typedef int (*nghttp2_on_stream_close_callback)
|
||||||
(nghttp2_session *session, int32_t stream_id, nghttp2_error_code error_code,
|
(nghttp2_session *session, int32_t stream_id, nghttp2_error_code error_code,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
|
||||||
* @functypedef
|
|
||||||
*
|
|
||||||
* Callback function invoked when the request from the remote peer is
|
|
||||||
* received. In other words, the frame with END_STREAM flag set is
|
|
||||||
* received. In HTTP, this means HTTP request, including request
|
|
||||||
* body, is fully received. The |user_data| pointer is the third
|
|
||||||
* argument passed in to the call to `nghttp2_session_client_new()` or
|
|
||||||
* `nghttp2_session_server_new()`.
|
|
||||||
*
|
|
||||||
* The implementation of this function must return 0 if it
|
|
||||||
* succeeds. If nonzero is returned, it is treated as fatal error and
|
|
||||||
* `nghttp2_session_recv()` and `nghttp2_session_send()` functions
|
|
||||||
* immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
|
|
||||||
*/
|
|
||||||
typedef int (*nghttp2_on_request_recv_callback)
|
|
||||||
(nghttp2_session *session, int32_t stream_id, void *user_data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @functypedef
|
* @functypedef
|
||||||
*
|
*
|
||||||
|
@ -1197,11 +1183,6 @@ typedef struct {
|
||||||
* Callback function invoked when the stream is closed.
|
* Callback function invoked when the stream is closed.
|
||||||
*/
|
*/
|
||||||
nghttp2_on_stream_close_callback on_stream_close_callback;
|
nghttp2_on_stream_close_callback on_stream_close_callback;
|
||||||
/**
|
|
||||||
* Callback function invoked when request from the remote peer is
|
|
||||||
* received.
|
|
||||||
*/
|
|
||||||
nghttp2_on_request_recv_callback on_request_recv_callback;
|
|
||||||
/**
|
/**
|
||||||
* Callback function invoked when the received frame type is
|
* Callback function invoked when the received frame type is
|
||||||
* unknown.
|
* unknown.
|
||||||
|
@ -1453,9 +1434,7 @@ int nghttp2_session_send(nghttp2_session *session);
|
||||||
* is invoked.
|
* is invoked.
|
||||||
* 2. If one DATA frame is completely received,
|
* 2. If one DATA frame is completely received,
|
||||||
* :member:`nghttp2_session_callbacks.on_frame_recv_callback` is
|
* :member:`nghttp2_session_callbacks.on_frame_recv_callback` is
|
||||||
* invoked. If the frame is the final frame of the request,
|
* invoked. If the reception of the frame triggers the
|
||||||
* :member:`nghttp2_session_callbacks.on_request_recv_callback`
|
|
||||||
* is invoked. If the reception of the frame triggers the
|
|
||||||
* closure of the stream,
|
* closure of the stream,
|
||||||
* :member:`nghttp2_session_callbacks.on_stream_close_callback`
|
* :member:`nghttp2_session_callbacks.on_stream_close_callback`
|
||||||
* is invoked.
|
* is invoked.
|
||||||
|
@ -1476,10 +1455,8 @@ int nghttp2_session_send(nghttp2_session *session);
|
||||||
* invoked. For other frames,
|
* invoked. For other frames,
|
||||||
* :member:`nghttp2_session_callbacks.on_frame_recv_callback` is
|
* :member:`nghttp2_session_callbacks.on_frame_recv_callback` is
|
||||||
* invoked.
|
* invoked.
|
||||||
* If the frame is the final frame of the request,
|
* If the reception of the frame triggers the closure of the
|
||||||
* :member:`nghttp2_session_callbacks.on_request_recv_callback`
|
* stream,
|
||||||
* is invoked. If the reception of the frame triggers the
|
|
||||||
* closure of the stream,
|
|
||||||
* :member:`nghttp2_session_callbacks.on_stream_close_callback`
|
* :member:`nghttp2_session_callbacks.on_stream_close_callback`
|
||||||
* is invoked.
|
* is invoked.
|
||||||
* 3. If the received frame is unpacked but is interpreted as
|
* 3. If the received frame is unpacked but is interpreted as
|
||||||
|
|
|
@ -1825,18 +1825,6 @@ static ssize_t nghttp2_recv(nghttp2_session *session, uint8_t *buf, size_t len)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nghttp2_session_call_on_request_recv
|
|
||||||
(nghttp2_session *session, int32_t stream_id)
|
|
||||||
{
|
|
||||||
if(session->callbacks.on_request_recv_callback) {
|
|
||||||
if(session->callbacks.on_request_recv_callback(session, stream_id,
|
|
||||||
session->user_data) != 0) {
|
|
||||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nghttp2_session_call_on_frame_received
|
static int nghttp2_session_call_on_frame_received
|
||||||
(nghttp2_session *session, nghttp2_frame *frame)
|
(nghttp2_session *session, nghttp2_frame *frame)
|
||||||
{
|
{
|
||||||
|
@ -2098,13 +2086,8 @@ int nghttp2_session_end_request_headers_received(nghttp2_session *session,
|
||||||
nghttp2_frame *frame,
|
nghttp2_frame *frame,
|
||||||
nghttp2_stream *stream)
|
nghttp2_stream *stream)
|
||||||
{
|
{
|
||||||
int rv;
|
|
||||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||||
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
|
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
|
||||||
rv = nghttp2_session_call_on_request_recv(session, frame->hd.stream_id);
|
|
||||||
if(rv != 0) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* Here we assume that stream is not shutdown in NGHTTP2_SHUT_WR */
|
/* Here we assume that stream is not shutdown in NGHTTP2_SHUT_WR */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2160,11 +2143,6 @@ int nghttp2_session_end_headers_received(nghttp2_session *session,
|
||||||
int rv;
|
int rv;
|
||||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||||
if(!nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) {
|
if(!nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) {
|
||||||
rv = nghttp2_session_call_on_request_recv(session,
|
|
||||||
frame->hd.stream_id);
|
|
||||||
if(rv != 0) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
|
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
|
||||||
rv = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
|
rv = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
|
||||||
|
@ -3168,14 +3146,6 @@ int nghttp2_session_on_data_received(nghttp2_session *session,
|
||||||
for now. */
|
for now. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) {
|
|
||||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
|
||||||
rv = nghttp2_session_call_on_request_recv(session, frame->hd.stream_id);
|
|
||||||
if(rv != 0) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||||
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
|
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
|
||||||
rv = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
|
rv = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
|
||||||
|
|
|
@ -185,8 +185,6 @@ int main(int argc, char* argv[])
|
||||||
test_nghttp2_session_flow_control_data_recv) ||
|
test_nghttp2_session_flow_control_data_recv) ||
|
||||||
!CU_add_test(pSuite, "session_data_read_temporal_failure",
|
!CU_add_test(pSuite, "session_data_read_temporal_failure",
|
||||||
test_nghttp2_session_data_read_temporal_failure) ||
|
test_nghttp2_session_data_read_temporal_failure) ||
|
||||||
!CU_add_test(pSuite, "session_on_request_recv_callback",
|
|
||||||
test_nghttp2_session_on_request_recv_callback) ||
|
|
||||||
!CU_add_test(pSuite, "session_on_stream_close",
|
!CU_add_test(pSuite, "session_on_stream_close",
|
||||||
test_nghttp2_session_on_stream_close) ||
|
test_nghttp2_session_on_stream_close) ||
|
||||||
!CU_add_test(pSuite, "session_on_ctrl_not_send",
|
!CU_add_test(pSuite, "session_on_ctrl_not_send",
|
||||||
|
|
|
@ -235,15 +235,6 @@ static ssize_t fail_data_source_read_callback
|
||||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int on_request_recv_callback(nghttp2_session *session,
|
|
||||||
int32_t stream_id,
|
|
||||||
void *user_data)
|
|
||||||
{
|
|
||||||
my_user_data *ud = (my_user_data*)user_data;
|
|
||||||
ud->stream_id = stream_id;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static void no_stream_user_data_stream_close_callback */
|
/* static void no_stream_user_data_stream_close_callback */
|
||||||
/* (nghttp2_session *session, */
|
/* (nghttp2_session *session, */
|
||||||
/* int32_t stream_id, */
|
/* int32_t stream_id, */
|
||||||
|
@ -3636,55 +3627,6 @@ void test_nghttp2_session_data_read_temporal_failure(void)
|
||||||
nghttp2_session_del(session);
|
nghttp2_session_del(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_nghttp2_session_on_request_recv_callback(void)
|
|
||||||
{
|
|
||||||
nghttp2_session *session;
|
|
||||||
nghttp2_session_callbacks callbacks;
|
|
||||||
my_user_data user_data;
|
|
||||||
nghttp2_frame frame;
|
|
||||||
nghttp2_stream *stream;
|
|
||||||
|
|
||||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
|
||||||
callbacks.on_request_recv_callback = on_request_recv_callback;
|
|
||||||
|
|
||||||
nghttp2_session_server_new(&session, &callbacks, &user_data);
|
|
||||||
nghttp2_frame_headers_init(&frame.headers,
|
|
||||||
NGHTTP2_FLAG_END_HEADERS |
|
|
||||||
NGHTTP2_FLAG_END_STREAM,
|
|
||||||
3, NGHTTP2_PRI_DEFAULT, NULL, 0);
|
|
||||||
|
|
||||||
/* nghttp2_session_end_* does not open stream, so we do it here */
|
|
||||||
stream = nghttp2_session_open_stream(session, 3, NGHTTP2_STREAM_FLAG_NONE,
|
|
||||||
NGHTTP2_PRI_DEFAULT,
|
|
||||||
NGHTTP2_STREAM_OPENING, NULL);
|
|
||||||
|
|
||||||
user_data.stream_id = 0;
|
|
||||||
CU_ASSERT(0 == nghttp2_session_end_request_headers_received
|
|
||||||
(session, &frame, stream));
|
|
||||||
CU_ASSERT(3 == user_data.stream_id);
|
|
||||||
|
|
||||||
nghttp2_frame_headers_free(&frame.headers);
|
|
||||||
|
|
||||||
user_data.stream_id = 0;
|
|
||||||
|
|
||||||
stream = nghttp2_session_open_stream(session, 5, NGHTTP2_STREAM_FLAG_NONE,
|
|
||||||
NGHTTP2_PRI_DEFAULT,
|
|
||||||
NGHTTP2_STREAM_OPENING, NULL);
|
|
||||||
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
|
|
||||||
5, NGHTTP2_PRI_DEFAULT, NULL, 0);
|
|
||||||
|
|
||||||
CU_ASSERT(0 == nghttp2_session_end_headers_received(session, &frame, stream));
|
|
||||||
CU_ASSERT(0 == user_data.stream_id);
|
|
||||||
|
|
||||||
frame.headers.hd.flags |= NGHTTP2_FLAG_END_STREAM;
|
|
||||||
|
|
||||||
CU_ASSERT(0 == nghttp2_session_end_headers_received(session, &frame, stream));
|
|
||||||
CU_ASSERT(5 == user_data.stream_id);
|
|
||||||
|
|
||||||
nghttp2_frame_headers_free(&frame.headers);
|
|
||||||
nghttp2_session_del(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_nghttp2_session_on_stream_close(void)
|
void test_nghttp2_session_on_stream_close(void)
|
||||||
{
|
{
|
||||||
nghttp2_session *session;
|
nghttp2_session *session;
|
||||||
|
|
|
@ -83,7 +83,6 @@ void test_nghttp2_session_flow_control_disable_remote(void);
|
||||||
void test_nghttp2_session_flow_control_disable_local(void);
|
void test_nghttp2_session_flow_control_disable_local(void);
|
||||||
void test_nghttp2_session_flow_control_data_recv(void);
|
void test_nghttp2_session_flow_control_data_recv(void);
|
||||||
void test_nghttp2_session_data_read_temporal_failure(void);
|
void test_nghttp2_session_data_read_temporal_failure(void);
|
||||||
void test_nghttp2_session_on_request_recv_callback(void);
|
|
||||||
void test_nghttp2_session_on_stream_close(void);
|
void test_nghttp2_session_on_stream_close(void);
|
||||||
void test_nghttp2_session_on_ctrl_not_send(void);
|
void test_nghttp2_session_on_ctrl_not_send(void);
|
||||||
void test_nghttp2_session_get_outbound_queue_size(void);
|
void test_nghttp2_session_get_outbound_queue_size(void);
|
||||||
|
|
Loading…
Reference in New Issue