diff --git a/lib/roles/http/private.h b/lib/roles/http/private.h index ad5496aaf..a0f9d9fe9 100644 --- a/lib/roles/http/private.h +++ b/lib/roles/http/private.h @@ -287,3 +287,6 @@ _lws_header_table_reset(struct allocated_headers *ah); LWS_EXTERN int _lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah); + +int +lws_http_get_uri_and_method(struct lws *wsi, char **puri_ptr, int *puri_len); diff --git a/lib/roles/http/server/access-log.c b/lib/roles/http/server/access-log.c index 41d9c71d9..74ae30ede 100644 --- a/lib/roles/http/server/access-log.c +++ b/lib/roles/http/server/access-log.c @@ -167,10 +167,14 @@ lws_access_log(struct lws *wsi) wsi->http.access_log.header_log, wsi->http.access_log.response, wsi->http.access_log.sent, p1); - if (strlen(p) > sizeof(ass) - 6 - l) + if (strlen(p) > sizeof(ass) - 6 - l) { p[sizeof(ass) - 6 - l] = '\0'; + l--; + } l += lws_snprintf(ass + l, sizeof(ass) - 1 - l, "\" \"%s\"\n", p); + ass[sizeof(ass) - 1] = '\0'; + if (write(wsi->vhost->log_fd, ass, l) != l) lwsl_err("Failed to write log\n"); diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index e488edf48..ed5258baa 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -882,7 +882,7 @@ static const unsigned char methods[] = { #endif }; -static int +int lws_http_get_uri_and_method(struct lws *wsi, char **puri_ptr, int *puri_len) { int n, count = 0; @@ -896,7 +896,7 @@ lws_http_get_uri_and_method(struct lws *wsi, char **puri_ptr, int *puri_len) } if (count != 1 && - !(wsi->http2_substream && + !((wsi->http2_substream || wsi->h2_stream_carries_ws) && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH))) { lwsl_warn("multiple methods?\n"); return -1; diff --git a/lib/roles/ws/server-ws.c b/lib/roles/ws/server-ws.c index 093aa1813..79cb6815f 100644 --- a/lib/roles/ws/server-ws.c +++ b/lib/roles/ws/server-ws.c @@ -270,40 +270,40 @@ lws_process_ws_upgrade(struct lws *wsi) */ #if defined(LWS_WITH_HTTP2) - if (wsi->http2_substream) - goto check_protocol; + if (!wsi->http2_substream) { #endif - lws_tokenize_init(&ts, buf, LWS_TOKENIZE_F_COMMA_SEP_LIST | - LWS_TOKENIZE_F_DOT_NONTERM | - LWS_TOKENIZE_F_RFC7230_DELIMS | - LWS_TOKENIZE_F_MINUS_NONTERM); - ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); - if (ts.len <= 0) - goto bad_conn_format; + lws_tokenize_init(&ts, buf, LWS_TOKENIZE_F_COMMA_SEP_LIST | + LWS_TOKENIZE_F_DOT_NONTERM | + LWS_TOKENIZE_F_RFC7230_DELIMS | + LWS_TOKENIZE_F_MINUS_NONTERM); + ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, + WSI_TOKEN_CONNECTION); + if (ts.len <= 0) + goto bad_conn_format; - do { - e = lws_tokenize(&ts); - switch (e) { - case LWS_TOKZE_TOKEN: - if (!strcasecmp(ts.token, "upgrade")) - e = LWS_TOKZE_ENDED; - break; + do { + e = lws_tokenize(&ts); + switch (e) { + case LWS_TOKZE_TOKEN: + if (!strcasecmp(ts.token, "upgrade")) + e = LWS_TOKZE_ENDED; + break; - case LWS_TOKZE_DELIMITER: - break; + case LWS_TOKZE_DELIMITER: + break; - default: /* includes ENDED */ -bad_conn_format: - lwsl_err("%s: malformed or absent connection hdr\n", - __func__); + default: /* includes ENDED */ + bad_conn_format: + lwsl_err("%s: malformed or absent conn hdr\n", + __func__); - return 1; - } - } while (e > 0); + return 1; + } + } while (e > 0); #if defined(LWS_WITH_HTTP2) -check_protocol: + } #endif /* @@ -485,6 +485,24 @@ alloc_ws: lws_server_init_wsi_for_ws(wsi); lwsl_parser("accepted v%02d connection\n", wsi->ws->ietf_spec_revision); +#if defined(LWS_WITH_ACCESS_LOG) + { + char *uptr = NULL, combo[128]; + int l, meth = lws_http_get_uri_and_method(wsi, &uptr, &l); + + if (wsi->h2_stream_carries_ws) + wsi->http.request_version = HTTP_VERSION_2; + + wsi->http.access_log.response = 101; + + l = lws_snprintf(combo, sizeof(combo), "%.*s (%s)", l, uptr, + wsi->protocol->name); + + lws_prepare_access_log_info(wsi, combo, l, meth); + lws_access_log(wsi); + } +#endif + lwsl_info("%s: %p: dropping ah on ws upgrade\n", __func__, wsi); lws_header_table_detach(wsi, 1);