http2: convert HEADER frames to HTTP1-like headers

... and then go through the "normal" HTTP engine.
This commit is contained in:
Daniel Stenberg 2014-01-30 15:58:07 +01:00
parent 93f473c78a
commit a7affd637f
2 changed files with 21 additions and 15 deletions

View File

@ -156,7 +156,7 @@ struct http_conn {
uint8_t binsettings[H2_BINSETTINGS_LEN]; uint8_t binsettings[H2_BINSETTINGS_LEN];
size_t binlen; /* length of the binsettings data */ size_t binlen; /* length of the binsettings data */
char *mem; /* points to a buffer in memory to store or read from */ char *mem; /* points to a buffer in memory to store or read from */
size_t size; /* size of the buffer 'mem' points to */ size_t len; /* size of the buffer 'mem' points to */
ssize_t nread; /* how much data that was sent/recv by the HTTP2 engine */ ssize_t nread; /* how much data that was sent/recv by the HTTP2 engine */
#else #else
int unused; /* prevent a compiler warning */ int unused; /* prevent a compiler warning */

View File

@ -62,7 +62,7 @@ const struct Curl_handler Curl_handler_http2 = {
ZERO_NULL, /* disconnect */ ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */ ZERO_NULL, /* readwrite */
PORT_HTTP, /* defport */ PORT_HTTP, /* defport */
0, /* protocol */ CURLPROTO_HTTP, /* protocol */
PROTOPT_NONE /* flags */ PROTOPT_NONE /* flags */
}; };
@ -247,22 +247,28 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
void *userp) void *userp)
{ {
struct connectdata *conn = (struct connectdata *)userp; struct connectdata *conn = (struct connectdata *)userp;
struct http_conn *c = &conn->proto.httpc;
size_t hlen = namelen + valuelen + 3; /* colon + CRLF == 3 bytes */
(void)session; (void)session;
(void)frame; (void)frame;
if(namelen + valuelen < 200) { if(namelen && (name[0] == ':')) {
char buffer[256]; /* special case */
memcpy(buffer, name, namelen); hlen = snprintf(c->mem, c->len, "HTTP/2.0 %s\r\n", value);
buffer[namelen]=':';
memcpy(&buffer[namelen+1], value, valuelen);
buffer[namelen + valuelen + 1]=0;
infof(conn->data, "Got '%s'\n", buffer);
/* TODO: the headers need to be passed to the http parser */
} }
else { else if(hlen + 1 < c->len) { /* hlen + a zero byte */
infof(conn->data, "Got header with no name or too long\n", /* convert to a HTTP1-style header */
namelen, name, valuelen, value); memcpy(c->mem, name, namelen);
c->mem[namelen]=':';
memcpy(&c->mem[namelen+1], value, valuelen);
c->mem[namelen + valuelen + 1]='\r';
c->mem[namelen + valuelen + 2]='\n';
c->mem[namelen + valuelen + 3]=0; /* to display this easier */
} }
infof(conn->data, "Got %s", c->mem);
c->mem += hlen;
c->len -= hlen;
return 0; /* 0 is successful */ return 0; /* 0 is successful */
} }
@ -376,7 +382,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
(void)sockindex; /* we always do HTTP2 on sockindex 0 */ (void)sockindex; /* we always do HTTP2 on sockindex 0 */
conn->proto.httpc.mem = mem; conn->proto.httpc.mem = mem;
conn->proto.httpc.size = len; conn->proto.httpc.len = len;
rc = nghttp2_session_recv(conn->proto.httpc.h2); rc = nghttp2_session_recv(conn->proto.httpc.h2);
@ -385,7 +391,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
rc); rc);
*err = CURLE_RECV_ERROR; *err = CURLE_RECV_ERROR;
} }
return 0; return len - conn->proto.httpc.len;
} }
/* return number of received (decrypted) bytes */ /* return number of received (decrypted) bytes */