Skip to content

Commit

Permalink
support h2 / h2c in addition to -14, -16
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Feb 18, 2015
1 parent 91403ce commit c687a01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/http1.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ static void set_timeout(h2o_http1_conn_t *conn, h2o_timeout_t *timeout, h2o_time
static void process_request(h2o_http1_conn_t *conn)
{
if (conn->sock->ssl == NULL && conn->req.upgrade.base != NULL && conn->super.ctx->globalconf->http1.upgrade_to_http2 &&
h2o_lcstris(conn->req.upgrade.base, conn->req.upgrade.len, H2O_STRLIT("h2c-14"))) {
conn->req.upgrade.len >= 3 && h2o_lcstris(conn->req.upgrade.base, 3, H2O_STRLIT("h2c")) &&
(conn->req.upgrade.len == 3 ||
(conn->req.upgrade.len == 6 && (memcmp(conn->req.upgrade.base + 3, H2O_STRLIT("-14")) == 0 ||
memcmp(conn->req.upgrade.base + 3, H2O_STRLIT("-16")) == 0)))) {
if (h2o_http2_handle_upgrade(&conn->req) == 0) {
return;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/http2/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@

static const h2o_iovec_t CONNECTION_PREFACE = {H2O_STRLIT("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")};

static const h2o_iovec_t alpn_protocols[] = {{H2O_STRLIT("h2-16")}, /* the lastest draft */
{H2O_STRLIT("h2-14")}, /* keep draft-14 for compatibility */
{NULL, 0}};
/* h2-14 and h2-16 are kept for backwards compatibility, as they are often used */
static const h2o_iovec_t alpn_protocols[] = {{H2O_STRLIT("h2")}, {H2O_STRLIT("h2-16")}, {H2O_STRLIT("h2-14")}, {NULL, 0}};
const h2o_iovec_t *h2o_http2_alpn_protocols = alpn_protocols;
/* npn defs should match the definition of alpn_protocols */
const char *h2o_http2_npn_protocols = "\x05"
const char *h2o_http2_npn_protocols = "\x02"
"h2"
"\x05"
"h2-16"
"\x05"
"h2-14";
Expand Down

0 comments on commit c687a01

Please sign in to comment.