1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

http: log ws upgrades

This commit is contained in:
Andy Green 2019-02-20 07:47:48 +08:00
parent 281d2a7fc2
commit 572ffb4a7c
4 changed files with 54 additions and 29 deletions

View file

@ -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);

View file

@ -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");

View file

@ -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;

View file

@ -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);