mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
http2 add h2c upgrade and http2 connmode
Connection upgrade handling for h2c Establish http2 union struct and http2 connmode No protocol code yet Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
1ee42a5f05
commit
a54f232f07
4 changed files with 36 additions and 1 deletions
|
@ -353,6 +353,8 @@ enum connection_mode {
|
|||
|
||||
LWS_CONNMODE_WS_SERVING,
|
||||
LWS_CONNMODE_WS_CLIENT,
|
||||
|
||||
LWS_CONNMODE_HTTP2_SERVING,
|
||||
|
||||
/* transient, ssl delay hiding */
|
||||
LWS_CONNMODE_SSL_ACK_PENDING,
|
||||
|
@ -552,6 +554,9 @@ struct _lws_http_mode_related {
|
|||
int content_remain;
|
||||
};
|
||||
|
||||
struct _lws_http2_related {
|
||||
};
|
||||
|
||||
struct _lws_header_related {
|
||||
struct allocated_headers *ah;
|
||||
short lextable_pos;
|
||||
|
@ -635,6 +640,7 @@ struct libwebsocket {
|
|||
|
||||
union u {
|
||||
struct _lws_http_mode_related http;
|
||||
struct _lws_http2_related http2;
|
||||
struct _lws_header_related hdr;
|
||||
struct _lws_websocket_related ws;
|
||||
} u;
|
||||
|
|
26
lib/server.c
26
lib/server.c
|
@ -358,11 +358,37 @@ int lws_handshake_server(struct libwebsocket_context *context,
|
|||
"websocket"))
|
||||
goto upgrade_ws;
|
||||
|
||||
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
|
||||
"h2c"))
|
||||
goto upgrade_h2c;
|
||||
|
||||
/* dunno what he wanted to upgrade to */
|
||||
goto bail_nuke_ah;
|
||||
|
||||
upgrade_h2c:
|
||||
|
||||
strcpy(protocol_list, "HTTP/1.1 101 Switching Protocols\x0d\x0a"
|
||||
"Connection: Upgrade\x0d\x0a"
|
||||
"Upgrade: h2c\x0d\x0a\x0d\x0a");
|
||||
n = libwebsocket_write(wsi, (unsigned char *)protocol_list,
|
||||
strlen(protocol_list), LWS_WRITE_HTTP);
|
||||
if (n != strlen(protocol_list)) {
|
||||
lwsl_debug("http2 switch: ERROR writing to socket\n");
|
||||
goto bail_nuke_ah;
|
||||
}
|
||||
|
||||
/* drop the header info -- no bail_nuke_ah after this */
|
||||
|
||||
if (wsi->u.hdr.ah)
|
||||
free(wsi->u.hdr.ah);
|
||||
|
||||
wsi->mode = LWS_CONNMODE_HTTP2_SERVING;
|
||||
|
||||
/* union transition */
|
||||
memset(&wsi->u, 0, sizeof(wsi->u));
|
||||
|
||||
return 0;
|
||||
|
||||
upgrade_ws:
|
||||
if (!wsi->protocol)
|
||||
lwsl_err("NULL protocol at libwebsocket_read\n");
|
||||
|
|
|
@ -471,6 +471,9 @@ drain:
|
|||
goto read_pending;
|
||||
break;
|
||||
|
||||
case LWS_CONNMODE_HTTP2_SERVING:
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef LWS_NO_CLIENT
|
||||
break;
|
||||
|
|
|
@ -857,7 +857,7 @@ int main(int argc, char **argv)
|
|||
lws_set_log_level(debug_level, lwsl_emit_syslog);
|
||||
|
||||
lwsl_notice("libwebsockets test server - "
|
||||
"(C) Copyright 2010-2013 Andy Green <andy@warmcat.com> - "
|
||||
"(C) Copyright 2010-2014 Andy Green <andy@warmcat.com> - "
|
||||
"licensed under LGPL2.1\n");
|
||||
#ifdef EXTERNAL_POLL
|
||||
max_poll_elements = getdtablesize();
|
||||
|
|
Loading…
Add table
Reference in a new issue