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 * @enum
* *
* The category of HEADERS, which indicates the role of the frame. In * The category of HEADERS, which indicates the role of the frame. In
* HTTP/2.0 spec, request HEADERS and response HEADERS and other * HTTP/2.0 spec, request, response, push response and other arbitrary
* arbitrary sent HEADERS are all called just HEADERS. In SPDY days, * headers (e.g., trailers) are all called just HEADERS. To give the
* they are called as SYN_STREAM, SYN_REPLY and HEADERS and which is * application the role of incoming HEADERS frame, we define several
* self-explanatory and easy to code. To give the application the * categories.
* particular HEADERS frame is analogous to the SPDY terms, we define
* 3 categories for it.
*/ */
typedef enum { typedef enum {
/** /**
* The HEADERS frame is opening stream, which is analogous to SPDY * The HEADERS frame is opening new stream, which is analogous to
* SYN_STREAM. * SYN_STREAM in SPDY.
*/ */
NGHTTP2_HCAT_START_STREAM, NGHTTP2_HCAT_REQUEST,
/** /**
* The HEADERS frame is the first response headers, which is * 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, * 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_HCAT_HEADERS,
} nghttp2_headers_category; } nghttp2_headers_category;

View File

@ -203,7 +203,7 @@ void nghttp2_frame_headers_init(nghttp2_headers *frame,
frame->pri = pri; frame->pri = pri;
frame->nva = nva; frame->nva = nva;
frame->nvlen = nvlen; frame->nvlen = nvlen;
frame->cat = NGHTTP2_HCAT_START_STREAM; frame->cat = NGHTTP2_HCAT_REQUEST;
} }
void nghttp2_frame_headers_free(nghttp2_headers *frame) 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); frame = nghttp2_outbound_item_get_ctrl_frame(item);
switch(frame->hd.type) { switch(frame->hd.type) {
case NGHTTP2_HEADERS: { case NGHTTP2_HEADERS: {
int push_reply = 0;
if(frame->hd.stream_id == -1) { if(frame->hd.stream_id == -1) {
/* initial HEADERS, which opens stream */ /* initial HEADERS, which opens stream */
int r; int r;
frame->headers.cat = NGHTTP2_HCAT_START_STREAM; frame->headers.cat = NGHTTP2_HCAT_REQUEST;
r = nghttp2_session_predicate_syn_stream_send(session, r = nghttp2_session_predicate_syn_stream_send(session,
&frame->headers); &frame->headers);
if(r != 0) { if(r != 0) {
@ -916,13 +915,10 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
session->next_stream_id += 2; session->next_stream_id += 2;
} else if(nghttp2_session_predicate_push_reply_send } else if(nghttp2_session_predicate_push_reply_send
(session, frame->hd.stream_id) == 0) { (session, frame->hd.stream_id) == 0) {
/* HEADERS against promised stream */ frame->headers.cat = NGHTTP2_HCAT_PUSH_RESPONSE;
push_reply = 1;
frame->headers.cat = NGHTTP2_HCAT_REPLY;
} else if(nghttp2_session_predicate_syn_reply_send } else if(nghttp2_session_predicate_syn_reply_send
(session, frame->hd.stream_id) == 0) { (session, frame->hd.stream_id) == 0) {
/* first response HEADERS */ frame->headers.cat = NGHTTP2_HCAT_RESPONSE;
frame->headers.cat = NGHTTP2_HCAT_REPLY;
} else { } else {
int r; int r;
frame->headers.cat = NGHTTP2_HCAT_HEADERS; frame->headers.cat = NGHTTP2_HCAT_HEADERS;
@ -940,7 +936,8 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session,
if(framebuflen < 0) { if(framebuflen < 0) {
return framebuflen; return framebuflen;
} }
if(frame->headers.cat == NGHTTP2_HCAT_START_STREAM) { switch(frame->headers.cat) {
case NGHTTP2_HCAT_REQUEST: {
nghttp2_headers_aux_data *aux_data; nghttp2_headers_aux_data *aux_data;
aux_data = (nghttp2_headers_aux_data*)item->aux_data; aux_data = (nghttp2_headers_aux_data*)item->aux_data;
if(nghttp2_session_open_stream 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) { aux_data ? aux_data->stream_user_data : NULL) == NULL) {
return NGHTTP2_ERR_NOMEM; return NGHTTP2_ERR_NOMEM;
} }
} else if(push_reply) { break;
}
case NGHTTP2_HCAT_PUSH_RESPONSE: {
nghttp2_headers_aux_data *aux_data; nghttp2_headers_aux_data *aux_data;
aux_data = (nghttp2_headers_aux_data*)item->aux_data; aux_data = (nghttp2_headers_aux_data*)item->aux_data;
if(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 = nghttp2_session_get_stream(session, frame->hd.stream_id);
stream->stream_user_data = aux_data->stream_user_data; stream->stream_user_data = aux_data->stream_user_data;
} }
break;
}
default:
break;
} }
break; break;
} }
@ -1241,7 +1244,7 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session)
nghttp2_headers_aux_data *aux_data; nghttp2_headers_aux_data *aux_data;
if(stream) { if(stream) {
switch(frame->headers.cat) { switch(frame->headers.cat) {
case NGHTTP2_HCAT_START_STREAM: { case NGHTTP2_HCAT_REQUEST: {
stream->state = NGHTTP2_STREAM_OPENING; stream->state = NGHTTP2_STREAM_OPENING;
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR);
@ -1263,7 +1266,8 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session)
} }
break; break;
} }
case NGHTTP2_HCAT_REPLY: case NGHTTP2_HCAT_RESPONSE:
case NGHTTP2_HCAT_PUSH_RESPONSE:
stream->state = NGHTTP2_STREAM_OPENED; stream->state = NGHTTP2_STREAM_OPENED;
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); 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 * 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. * succeeds, or non-zero nghttp2_error_code.
*/ */
static int nghttp2_session_validate_syn_stream(nghttp2_session *session, 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(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)) {
if(stream->state == NGHTTP2_STREAM_OPENING) { 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); r = nghttp2_session_on_syn_reply_received(session, &frame, stream);
} else { } else {
frame.headers.cat = NGHTTP2_HCAT_HEADERS; frame.headers.cat = NGHTTP2_HCAT_HEADERS;
@ -2278,14 +2282,14 @@ static int nghttp2_session_process_ctrl_frame(nghttp2_session *session)
} }
} else if(!session->server && } else if(!session->server &&
stream->state == NGHTTP2_STREAM_RESERVED) { 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); r = nghttp2_session_on_push_reply_received(session, &frame, stream);
} else { } else {
frame.headers.cat = NGHTTP2_HCAT_HEADERS; frame.headers.cat = NGHTTP2_HCAT_HEADERS;
r = nghttp2_session_on_headers_received(session, &frame, stream); r = nghttp2_session_on_headers_received(session, &frame, stream);
} }
} else { } else {
frame.headers.cat = NGHTTP2_HCAT_START_STREAM; frame.headers.cat = NGHTTP2_HCAT_REQUEST;
r = nghttp2_session_on_syn_stream_received(session, &frame); r = nghttp2_session_on_syn_stream_received(session, &frame);
} }
nghttp2_frame_headers_free(&frame.headers); nghttp2_frame_headers_free(&frame.headers);

View File

@ -687,7 +687,7 @@ void hd_on_frame_recv_callback
switch(frame->hd.type) { switch(frame->hd.type) {
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
switch(frame->headers.cat) { switch(frame->headers.cat) {
case NGHTTP2_HCAT_START_STREAM: { case NGHTTP2_HCAT_REQUEST: {
int32_t stream_id = frame->hd.stream_id; int32_t stream_id = frame->hd.stream_id;
auto req = util::make_unique<Request>(stream_id); auto req = util::make_unique<Request>(stream_id);
append_nv(req.get(), frame->headers.nva, frame->headers.nvlen); 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); printf("(pri=%d)\n", frame->headers.pri);
} }
switch(frame->headers.cat) { switch(frame->headers.cat) {
case NGHTTP2_HCAT_START_STREAM: case NGHTTP2_HCAT_REQUEST:
print_frame_attr_indent(); print_frame_attr_indent();
printf("; Open new stream\n"); printf("; Open new stream\n");
break; break;
case NGHTTP2_HCAT_REPLY: case NGHTTP2_HCAT_RESPONSE:
print_frame_attr_indent(); print_frame_attr_indent();
printf("; First response header\n"); printf("; First response header\n");
break; break;
case NGHTTP2_HCAT_PUSH_RESPONSE:
print_frame_attr_indent();
printf("; First push response header\n");
break;
default: default:
break; break;
} }

View File

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