mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
Pass HTTP reject error code returned by server to client
Signed-off-by: Gadkari Mugdha <mugdha.gadkari@siemens.com> Reviewed-by: Roger Meier <r.meier@siemens.com> HTTP reject error code returned by server during HTTP handshake is extracted and sent to the client application. With this fix, the Connection error callback will include the HTTP reject status code and response frame received from server. This string passed in Connection error callback can be read or ignored by client application based on client application requirement
This commit is contained in:
parent
3ae1badae7
commit
8907b0073d
1 changed files with 14 additions and 4 deletions
18
lib/client.c
18
lib/client.c
|
@ -481,6 +481,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|||
int okay = 0;
|
||||
char *p;
|
||||
int len;
|
||||
int isErrorCodeReceived = 0;
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
char ext_name[128];
|
||||
struct libwebsocket_extension *ext;
|
||||
|
@ -498,6 +499,8 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|||
|
||||
if (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) {
|
||||
lwsl_info("no ACCEPT\n");
|
||||
p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP);
|
||||
isErrorCodeReceived = 1;
|
||||
goto bail3;
|
||||
}
|
||||
|
||||
|
@ -786,10 +789,17 @@ bail3:
|
|||
close_reason = LWS_CLOSE_STATUS_NOSTATUS;
|
||||
|
||||
bail2:
|
||||
if (wsi->protocol)
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
|
||||
wsi->user_space, NULL, 0);
|
||||
if (wsi->protocol) {
|
||||
if (isErrorCodeReceived && p) {
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
|
||||
wsi->user_space, p, (unsigned int)strlen(p));
|
||||
} else {
|
||||
wsi->protocol->callback(context, wsi,
|
||||
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
|
||||
wsi->user_space, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
lwsl_info("closing connection due to bail2 connection error\n");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue