Commit a85a11c1 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Update priority for the stream to get response only

parent 5aa487c5
......@@ -1501,9 +1501,24 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session)
}
break;
}
case NGHTTP2_PRIORITY:
/* nothing to do */
case NGHTTP2_PRIORITY: {
nghttp2_stream *stream;
stream = nghttp2_session_get_stream(session, frame->hd.stream_id);
if(!stream) {
break;
}
/* Only update priority of the stream, only if it is not pushed
stream and is initiated by local peer, or it is pushed stream
and is initiated by remote peer */
if(((stream->flags & NGHTTP2_STREAM_FLAG_PUSH) == 0 &&
nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) ||
((stream->flags & NGHTTP2_STREAM_FLAG_PUSH) &&
!nghttp2_session_is_my_stream_id(session, frame->hd.stream_id))) {
nghttp2_session_reprioritize_stream(session, stream,
frame->priority.pri);
}
break;
}
case NGHTTP2_RST_STREAM:
r = nghttp2_session_close_stream(session, frame->hd.stream_id,
frame->rst_stream.error_code);
......@@ -2157,8 +2172,13 @@ int nghttp2_session_on_priority_received(nghttp2_session *session,
return nghttp2_session_handle_invalid_connection(session, frame,
NGHTTP2_PROTOCOL_ERROR);
}
/* Only update priority on server side for now */
if(session->server) {
/* Only update priority of the stream, only if it is not pushed
stream and is initiated by remote peer, or it is pushed stream
and is initiated by local peer */
if(((stream->flags & NGHTTP2_STREAM_FLAG_PUSH) == 0 &&
!nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) ||
((stream->flags & NGHTTP2_STREAM_FLAG_PUSH) &&
nghttp2_session_is_my_stream_id(session, frame->hd.stream_id))) {
nghttp2_session_reprioritize_stream(session, stream,
frame->priority.pri);
}
......
......@@ -162,10 +162,6 @@ int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
free(frame);
return r;
}
/* Only update priority if the sender is client for now */
if(!session->server) {
nghttp2_session_reprioritize_stream(session, stream, pri);
}
return 0;
}
......
......@@ -1009,19 +1009,42 @@ void test_nghttp2_session_on_priority_received(void)
nghttp2_session_callbacks callbacks;
my_user_data user_data;
nghttp2_frame frame;
nghttp2_stream *stream;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.on_frame_recv_callback = on_frame_recv_callback;
callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback;
nghttp2_session_server_new(&session, &callbacks, &user_data);
nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
nghttp2_frame_priority_init(&frame.priority, 1, 1000000007);
/* non-push and initiated by remote peer */
CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));
CU_ASSERT(1000000007 == stream->pri);
/* push and initiated by remote peer: no update */
stream->flags = NGHTTP2_STREAM_FLAG_PUSH;
stream->pri = NGHTTP2_PRI_DEFAULT;
CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));
CU_ASSERT(NGHTTP2_PRI_DEFAULT == stream->pri);
stream = nghttp2_session_open_stream(session, 2, NGHTTP2_STREAM_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
frame.hd.stream_id = 2;
/* non-push and initiated by local peer: no update */
CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));
CU_ASSERT(NGHTTP2_PRI_DEFAULT == stream->pri);
/* push and initiated by local peer */
stream->flags = NGHTTP2_STREAM_FLAG_PUSH;
CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));
CU_ASSERT(1000000007 == nghttp2_session_get_stream(session, 1)->pri);
CU_ASSERT(1000000007 == stream->pri);
nghttp2_frame_priority_free(&frame.priority);
nghttp2_session_del(session);
......@@ -2231,11 +2254,37 @@ void test_nghttp2_submit_priority(void)
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT ==
nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, -1));
/* non-push stream and initiated by local peer */
CU_ASSERT(0 == nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1,
1000000007));
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(1000000007 == stream->pri);
/* push stream and initiated by local peer: no update */
stream->flags = NGHTTP2_STREAM_FLAG_PUSH;
stream->pri = NGHTTP2_PRI_DEFAULT;
CU_ASSERT(0 == nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1,
1000000007));
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(NGHTTP2_PRI_DEFAULT == stream->pri);
/* non-push stream and initiated by remote peer: no update */
stream = nghttp2_session_open_stream(session, 2, NGHTTP2_STREAM_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
CU_ASSERT(0 == nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 2,
1000000007));
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(NGHTTP2_PRI_DEFAULT == stream->pri);
/* push stream and initiated by remote peer */
stream->flags = NGHTTP2_STREAM_FLAG_PUSH;
CU_ASSERT(0 == nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 2,
1000000007));
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(1000000007 == stream->pri);
nghttp2_session_del(session);
/* Check that transmission of PRIORITY in reserved(local) is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment