From b0e2e50c754d4d064d2bbbdbb143903a981b5951 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 18 Oct 2014 18:54:04 +0800 Subject: [PATCH] http2 working nghttp fetch multi files completely Signed-off-by: Andy Green --- lib/hpack.c | 3 +++ lib/http2.c | 24 ++++++++++++++++++++++-- lib/output.c | 2 +- lib/ssl-http2.c | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/hpack.c b/lib/hpack.c index 4b2a1a8..37c4319 100644 --- a/lib/hpack.c +++ b/lib/hpack.c @@ -668,6 +668,9 @@ int lws_add_http2_header_status(struct libwebsocket_context *context, unsigned char status[10]; int n; + if (code >= 400) + wsi->u.http2.END_STREAM = 1; + n = sprintf((char *)status, "%u", code); if (lws_add_http2_header_by_token(context, wsi, WSI_TOKEN_HTTP_COLON_STATUS, status, n, p, end)) return 1; diff --git a/lib/http2.c b/lib/http2.c index ae96237..15e0793 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -344,6 +344,7 @@ update_end_headers: int lws_http2_do_pps_send(struct libwebsocket_context *context, struct libwebsocket *wsi) { unsigned char settings[LWS_SEND_BUFFER_PRE_PADDING + 6 * LWS_HTTP2_SETTINGS__COUNT]; + struct libwebsocket *swsi; int n, m = 0; switch (wsi->pps) { @@ -376,8 +377,27 @@ int lws_http2_do_pps_send(struct libwebsocket_context *context, struct libwebsoc wsi->state = WSI_STATE_HTTP2_ESTABLISHED; wsi->u.http.fd = LWS_INVALID_FILE; - - return 0; + + /* + * we need to treat the headers from this upgrade + * as the first job. These need to get + * shifted to stream ID 1 + */ + lwsl_info("%s: setting up sid 1\n", __func__); + + swsi = wsi->u.http2.stream_wsi = lws_create_server_child_wsi(context, wsi, 1); + /* pass on the initial headers to SID 1 */ + swsi->u.http.ah = wsi->u.http.ah; + wsi->u.http.ah = NULL; + + lwsl_info("%s: inherited headers %p\n", __func__, swsi->u.http.ah); + swsi->u.http2.tx_credit = wsi->u.http2.peer_settings.setting[LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE]; + lwsl_info("initial tx credit on conn %p: %d\n", swsi, swsi->u.http2.tx_credit); + swsi->u.http2.initialized = 1; + /* demanded by HTTP2 */ + swsi->u.http2.END_STREAM = 1; + lwsl_info("servicing initial http request\n"); + return lws_http_action(context, swsi); } break; default: diff --git a/lib/output.c b/lib/output.c index aebec9c..91c754a 100644 --- a/lib/output.c +++ b/lib/output.c @@ -456,7 +456,7 @@ send_raw: } } - if (protocol == LWS_WRITE_HTTP_FINAL && wsi->u.http2.END_STREAM) { + if ((protocol == LWS_WRITE_HTTP_FINAL || protocol == LWS_WRITE_HTTP_HEADERS) && wsi->u.http2.END_STREAM) { lwsl_info("%s: setting END_STREAM\n", __func__); flags |= LWS_HTTP2_FLAG_END_STREAM; } diff --git a/lib/ssl-http2.c b/lib/ssl-http2.c index 673bf67..a0ab277 100644 --- a/lib/ssl-http2.c +++ b/lib/ssl-http2.c @@ -72,7 +72,7 @@ lws_context_init_http2_ssl(struct libwebsocket_context *context) SSL_CTX_set_alpn_select_cb(context->ssl_ctx, alpn_select_proto_cb, NULL); lwsl_notice(" HTTP2 / ALPN enabled\n"); #else - lwsl_notice(" HTTP2 / ALPN configured but not supported by OpenSSL version\n"); + lwsl_notice(" HTTP2 / ALPN configured but not supported by OpenSSL version 0x%x\n", OPENSSL_VERSION_NUMBER); #endif // OPENSSL_VERSION_NUMBER >= 0x10002000L } -- 2.7.4