From 5cdc9c114db2d5f84c397861953e440d634794b4 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 18 Mar 2021 10:13:12 +0000 Subject: [PATCH] http_proxy: report failed http code Improve how we report what happened with http_proxy... if we can't recognize the response as http/1.0 or http/1.1 do a CCE with "http_proxy fail", or if we did get valid h1 response but no 200 response code, do a CCE with "http_proxy -> xxx" where xxx is the decimal representation of the response code, eg, "http_proxy -> 407" --- lib/roles/http/client/client-http.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index 1e6da7962..1d4eb61b1 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -118,13 +118,22 @@ lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) goto bail3; } + /* sanity check what we were sent... */ + pt->serv_buf[13] = '\0'; - if (n < 13 || (strncmp(sb, "HTTP/1.0 200 ", 13) && - strncmp(sb, "HTTP/1.1 200 ", 13))) { - lwsl_err("%s: ERROR proxy did not reply with h1\n", - __func__); + if (n < 13 || strncmp(sb, "HTTP/1.", 7) || + (sb[7] != '0' && sb[7] != '1') || sb[8] != ' ') { /* lwsl_hexdump_notice(sb, n); */ - cce = "proxy not h1"; + cce = "http_proxy fail"; + goto bail3; + } + + /* it's h1 alright... what's his logical response code? */ + n = atoi(&sb[9]); + if (n != 200) { + lws_snprintf(sb, 20, "http_proxy -> %u", + (unsigned int)n); + cce = sb; goto bail3; }