http2 working nghttp fetch multi files completely
authorAndy Green <andy.green@linaro.org>
Sat, 18 Oct 2014 10:54:04 +0000 (18:54 +0800)
committerAndy Green <andy.green@linaro.org>
Sat, 18 Oct 2014 10:54:04 +0000 (18:54 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/hpack.c
lib/http2.c
lib/output.c
lib/ssl-http2.c

index 4b2a1a8..37c4319 100644 (file)
@@ -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;
index ae96237..15e0793 100644 (file)
@@ -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:
index aebec9c..91c754a 100644 (file)
@@ -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;
                        }
index 673bf67..a0ab277 100644 (file)
@@ -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
 }