Rename nghttp2_headers_category members

Add NGHTTP2_HCAT_PUSH_RESPONSE
This commit is contained in:
Tatsuhiro Tsujikawa 2013-07-25 20:53:30 +09:00
parent 442e10cc78
commit 3cc71a707e
6 changed files with 45 additions and 34 deletions

View File

@ -449,27 +449,30 @@ typedef struct {
* @enum
*
* The category of HEADERS, which indicates the role of the frame. In
* HTTP/2.0 spec, request HEADERS and response HEADERS and other
* arbitrary sent HEADERS are all called just HEADERS. In SPDY days,
* they are called as SYN_STREAM, SYN_REPLY and HEADERS and which is
* self-explanatory and easy to code. To give the application the
* particular HEADERS frame is analogous to the SPDY terms, we define
* 3 categories for it.
* HTTP/2.0 spec, request, response, push response and other arbitrary
* headers (e.g., trailers) are all called just HEADERS. To give the
* application the role of incoming HEADERS frame, we define several
* categories.
*/
typedef enum {
/**
* The HEADERS frame is opening stream, which is analogous to SPDY
* SYN_STREAM.
* The HEADERS frame is opening new stream, which is analogous to
* SYN_STREAM in SPDY.
*/
NGHTTP2_HCAT_START_STREAM,
NGHTTP2_HCAT_REQUEST,
/**
* The HEADERS frame is the first response headers, which is
* analogous to SPDY SYN_REPLY.
* analogous to SYN_REPLY in SPDY.
*/
NGHTTP2_HCAT_REPLY,
NGHTTP2_HCAT_RESPONSE,
/**
* The HEADERS frame is the first headers sent against reserved
* stream.
*/
NGHTTP2_HCAT_PUSH_RESPONSE,
/**
* The HEADERS frame which does not apply for the above categories,
* which is analogous to SPDY HEADERS.
* which is analogous to HEADERS in SPDY.
*/
NGHTTP2_HCAT_HEADERS,
} nghttp2_headers_category;

View File

@ -203,7 +203,7 @@ void nghttp2_frame_headers_init(nghttp2_headers *frame,
frame->pri = pri;
frame->nva = nva;
frame->nvlen = nvlen;
frame->cat = NGHTTP2_HCAT_START_STREAM;
frame->cat = NGHTTP2_HCAT_REQUEST;
}
void nghttp2_frame_headers_free(nghttp2_headers *frame)

View File

@ -902,11 +902,10 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
frame = nghttp2_outbound_item_get_ctrl_frame(item);
switch(frame->hd.type) {
case NGHTTP2_HEADERS: {
int push_reply = 0;
if(frame->hd.stream_id == -1) {
/* initial HEADERS, which opens stream */
int r;
frame->headers.cat = NGHTTP2_HCAT_START_STREAM;
frame->headers.cat = NGHTTP2_HCAT_REQUEST;
r = nghttp2_session_predicate_syn_stream_send(session,
&frame->headers);
if(r != 0) {
@ -916,13 +915,10 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
session->next_stream_id += 2;
} else if(nghttp2_session_predicate_push_reply_send
(session, frame->hd.stream_id) == 0) {
/* HEADERS against promised stream */
push_reply = 1;
frame->headers.cat = NGHTTP2_HCAT_REPLY;
frame->headers.cat = NGHTTP2_HCAT_PUSH_RESPONSE;
} else if(nghttp2_session_predicate_syn_reply_send
(session, frame->hd.stream_id) == 0) {
/* first response HEADERS */
frame->headers.cat = NGHTTP2_HCAT_REPLY;
frame->headers.cat = NGHTTP2_HCAT_RESPONSE;
} else {
int r;
frame->headers.cat = NGHTTP2_HCAT_HEADERS;
@ -940,7 +936,8 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
if(framebuflen < 0) {
return framebuflen;
}
if(frame->headers.cat == NGHTTP2_HCAT_START_STREAM) {
switch(frame->headers.cat) {
case NGHTTP2_HCAT_REQUEST: {
nghttp2_headers_aux_data *aux_data;
aux_data = (nghttp2_headers_aux_data*)item->aux_data;
if(nghttp2_session_open_stream
@ -951,7 +948,9 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
aux_data ? aux_data->stream_user_data : NULL) == NULL) {
return NGHTTP2_ERR_NOMEM;
}
} else if(push_reply) {
break;
}
case NGHTTP2_HCAT_PUSH_RESPONSE: {
nghttp2_headers_aux_data *aux_data;
aux_data = (nghttp2_headers_aux_data*)item->aux_data;
if(aux_data) {
@ -959,6 +958,10 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
stream = nghttp2_session_get_stream(session, frame->hd.stream_id);
stream->stream_user_data = aux_data->stream_user_data;
}
break;
}
default:
break;
}
break;
}
@ -1241,7 +1244,7 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session)
nghttp2_headers_aux_data *aux_data;
if(stream) {
switch(frame->headers.cat) {
case NGHTTP2_HCAT_START_STREAM: {
case NGHTTP2_HCAT_REQUEST: {
stream->state = NGHTTP2_STREAM_OPENING;
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR);
@ -1263,7 +1266,8 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session)
}
break;
}
case NGHTTP2_HCAT_REPLY:
case NGHTTP2_HCAT_RESPONSE:
case NGHTTP2_HCAT_PUSH_RESPONSE:
stream->state = NGHTTP2_STREAM_OPENED;
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR);
@ -1583,7 +1587,7 @@ static int nghttp2_session_is_new_peer_stream_id(nghttp2_session *session,
/*
* Validates received HEADERS frame |frame| with
* NGHTTP2_HCAT_START_STREAM category_. This function returns 0 if it
* NGHTTP2_HCAT_REQUEST category_. This function returns 0 if it
* succeeds, or non-zero nghttp2_error_code.
*/
static int nghttp2_session_validate_syn_stream(nghttp2_session *session,
@ -2270,7 +2274,7 @@ static int nghttp2_session_process_ctrl_frame(nghttp2_session *session)
if(stream) {
if(nghttp2_session_is_my_stream_id(session, frame.hd.stream_id)) {
if(stream->state == NGHTTP2_STREAM_OPENING) {
frame.headers.cat = NGHTTP2_HCAT_REPLY;
frame.headers.cat = NGHTTP2_HCAT_RESPONSE;
r = nghttp2_session_on_syn_reply_received(session, &frame, stream);
} else {
frame.headers.cat = NGHTTP2_HCAT_HEADERS;
@ -2278,14 +2282,14 @@ static int nghttp2_session_process_ctrl_frame(nghttp2_session *session)
}
} else if(!session->server &&
stream->state == NGHTTP2_STREAM_RESERVED) {
frame.headers.cat = NGHTTP2_HCAT_REPLY;
frame.headers.cat = NGHTTP2_HCAT_PUSH_RESPONSE;
r = nghttp2_session_on_push_reply_received(session, &frame, stream);
} else {
frame.headers.cat = NGHTTP2_HCAT_HEADERS;
r = nghttp2_session_on_headers_received(session, &frame, stream);
}
} else {
frame.headers.cat = NGHTTP2_HCAT_START_STREAM;
frame.headers.cat = NGHTTP2_HCAT_REQUEST;
r = nghttp2_session_on_syn_stream_received(session, &frame);
}
nghttp2_frame_headers_free(&frame.headers);

View File

@ -687,7 +687,7 @@ void hd_on_frame_recv_callback
switch(frame->hd.type) {
case NGHTTP2_HEADERS:
switch(frame->headers.cat) {
case NGHTTP2_HCAT_START_STREAM: {
case NGHTTP2_HCAT_REQUEST: {
int32_t stream_id = frame->hd.stream_id;
auto req = util::make_unique<Request>(stream_id);
append_nv(req.get(), frame->headers.nva, frame->headers.nvlen);

View File

@ -229,14 +229,18 @@ void print_frame(print_type ptype, nghttp2_frame *frame)
printf("(pri=%d)\n", frame->headers.pri);
}
switch(frame->headers.cat) {
case NGHTTP2_HCAT_START_STREAM:
case NGHTTP2_HCAT_REQUEST:
print_frame_attr_indent();
printf("; Open new stream\n");
break;
case NGHTTP2_HCAT_REPLY:
case NGHTTP2_HCAT_RESPONSE:
print_frame_attr_indent();
printf("; First response header\n");
break;
case NGHTTP2_HCAT_PUSH_RESPONSE:
print_frame_attr_indent();
printf("; First push response header\n");
break;
default:
break;
}

View File

@ -745,7 +745,7 @@ void on_frame_send_callback2
(nghttp2_session *session, nghttp2_frame *frame, void *user_data)
{
if(frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_START_STREAM) {
frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
check_stream_id(session, frame, user_data);
}
if(config.verbose) {
@ -757,7 +757,7 @@ void check_response_header
(nghttp2_session *session, nghttp2_frame *frame, void *user_data)
{
if(frame->hd.type != NGHTTP2_HEADERS ||
frame->headers.cat != NGHTTP2_HCAT_REPLY) {
frame->headers.cat != NGHTTP2_HCAT_RESPONSE) {
return;
}
auto req = (Request*)nghttp2_session_get_stream_user_data
@ -792,7 +792,7 @@ void on_frame_recv_callback2
(nghttp2_session *session, nghttp2_frame *frame, void *user_data)
{
if(frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_REPLY) {
frame->headers.cat == NGHTTP2_HCAT_RESPONSE) {
auto req = (Request*)nghttp2_session_get_stream_user_data
(session, frame->hd.stream_id);
assert(req);