[Libwebsockets] Logging WS HS

Andy Green andy at warmcat.com
Sat Mar 7 21:23:11 CET 2020



On 3/7/20 5:01 PM, Olivier Langlois wrote:
> On Sun, 2020-03-01 at 18:27 +0000, Andy Green wrote:
\
>> OK.  Wrt to your user code example above, 4xx or 5xx not just 503
>> should
>> get this new treatment, otherwise it looks good AFAICS.  Maybe it can
>> do
>> with a new public macro to definitively tell the user code if the
>> status
>> is "failed".
> 
> You are correct that I should check for other codes as well. It is just
> that AFAIK, the only error code that the used service can return is
> 503. I'm taking a small shortcut just to make a quick proof of concept
> prototype.
> 
> I guess that if we were to add the new public macro, this is what I
> would use in my code.
> 
> So today, the used service did enter into a maintenance mode and this
> did allowed me to test my proposed patch.
> 
> 1. It works like a charm! Here is the trace log:
> 
> [2020-03-07  11:05:16] INFO WSBASE/callback
> LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: 0
> [2020-03-07  11:05:16] INFO WSCONT/log_emit_function 0:
> lws_http_client_read: rlen 178
> 
> [2020-03-07  11:05:16] INFO WSCONT/log_emit_function 0: chunk 172
> 
> [2020-03-07  11:05:16] INFO WSBASE/callback HTTP 503 reply body:
> <html>
> <head><title>503 Service Temporarily Unavailable</title></head>
> <body bgcolor="white">
> <center><h1>503 Service Temporarily Unavailable</h1></center>
> </body>
> </html>
> 
> [2020-03-07  11:05:16] WARN WSCONT/log_emit_function 0:
> lws_client_handshake: got bad HTTP response '503'
> 
> [2020-03-07  11:05:16] EROR WSBASE/connection_error
> CLIENT_CONNECTION_ERROR: HS: ws upgrade response not 101
> [2020-03-07  11:05:16] INFO WS/getReconnTO Retrying in 256 seconds
> [2020-03-07  11:05:16] INFO WSBASE/callback
> LWS_CALLBACK_CLOSED_CLIENT_HTTP
> [2020-03-07  11:05:16] INFO WSBASE/callback LWS_CALLBACK_WSI_DESTROY

Thanks... there's a cut-and-paste error stopping it building as you 
attached it

diff --git a/lib/roles/http/client/client-http.c 
b/lib/roles/http/client/client-http.c
index 2462bfc1b..5509c74ba 100644
--- a/lib/roles/http/client/client-http.c
+++ b/lib/roles/http/client/client-http.c
@@ -834,9 +834,9 @@ lws_client_interpret_server_handshake(struct lws *wsi)
                  * before the ws upgrade code discard it. ie: download 
reply body in case
                  * of any other response code than 101.
                  */
-               if (w->protocol->callback(w,
+               if (wsi->protocol->callback(wsi,
 
LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP,
-                                         w->user_space, NULL, 0)) {
+                                         wsi->user_space, NULL, 0)) {

                         cce = "HS: disallowed by client filter";
                         goto bail2;


> 2. Is the only thing missing to integrate the patch is the macro()?
> 
> How about:
> 
> /**
>   * lws_http_client_http_error() - determine if the response code
> indicates an error
>   *
>   * \param code: the response code to test
>   *
>   * Returns 0 if the code indicates an error or nonzero
>   *
>   */
> #define lws_http_client_http_error(code) (!(code >= 400))
> 
> ?

It's good but the convention seems to be that test macros return nonzero 
for true... I modified it and the name a bit and pushed that and the 
patch on master.

-Andy


More information about the Libwebsockets mailing list