[core,gateway] unify http response logging
This commit is contained in:
parent
0bdb62e9b5
commit
cd7cb514a8
@ -423,9 +423,7 @@ BOOL arm_resolve_endpoint(rdpContext* context, DWORD timeout)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char buffer[64] = { 0 };
|
http_response_log_error_status(WLog_Get(TAG), WLOG_ERROR, response);
|
||||||
WLog_ERR(TAG, "Unexpected HTTP status: %s",
|
|
||||||
freerdp_http_status_string_format(StatusCode, buffer, ARRAYSIZE(buffer)));
|
|
||||||
goto arm_error;
|
goto arm_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -955,17 +955,15 @@ fail:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL http_response_print(HttpResponse* response)
|
static void http_response_print(wLog* log, DWORD level, HttpResponse* response)
|
||||||
{
|
{
|
||||||
size_t i;
|
WINPR_ASSERT(log);
|
||||||
|
WINPR_ASSERT(response);
|
||||||
|
|
||||||
if (!response)
|
if (!WLog_IsLevelActive(log, level))
|
||||||
return FALSE;
|
return;
|
||||||
|
for (size_t i = 0; i < response->count; i++)
|
||||||
for (i = 0; i < response->count; i++)
|
WLog_Print(log, level, "[%" PRIuz "] %s", i, response->lines[i]);
|
||||||
WLog_ERR(TAG, "%s", response->lines[i]);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL http_use_content_length(const char* cur)
|
static BOOL http_use_content_length(const char* cur)
|
||||||
@ -1437,16 +1435,14 @@ BOOL http_request_set_content_length(HttpRequest* request, size_t length)
|
|||||||
|
|
||||||
long http_response_get_status_code(HttpResponse* response)
|
long http_response_get_status_code(HttpResponse* response)
|
||||||
{
|
{
|
||||||
if (!response)
|
WINPR_ASSERT(response);
|
||||||
return -1;
|
|
||||||
|
|
||||||
return response->StatusCode;
|
return response->StatusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSIZE_T http_response_get_body_length(HttpResponse* response)
|
size_t http_response_get_body_length(HttpResponse* response)
|
||||||
{
|
{
|
||||||
if (!response)
|
WINPR_ASSERT(response);
|
||||||
return -1;
|
|
||||||
|
|
||||||
return (SSIZE_T)response->BodyLength;
|
return (SSIZE_T)response->BodyLength;
|
||||||
}
|
}
|
||||||
@ -1532,3 +1528,18 @@ out:
|
|||||||
free(base64accept);
|
free(base64accept);
|
||||||
return isWebsocket;
|
return isWebsocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void http_response_log_error_status(wLog* log, DWORD level, HttpResponse* response)
|
||||||
|
{
|
||||||
|
WINPR_ASSERT(log);
|
||||||
|
WINPR_ASSERT(response);
|
||||||
|
|
||||||
|
if (!WLog_IsLevelActive(log, level))
|
||||||
|
return;
|
||||||
|
|
||||||
|
char buffer[64] = { 0 };
|
||||||
|
const long status = http_response_get_status_code(response);
|
||||||
|
WLog_Print(log, level, "Unexpected HTTP status: %s",
|
||||||
|
freerdp_http_status_string_format(status, buffer, ARRAYSIZE(buffer)));
|
||||||
|
http_response_print(log, level, response);
|
||||||
|
}
|
||||||
|
@ -101,17 +101,18 @@ typedef struct s_http_response HttpResponse;
|
|||||||
FREERDP_LOCAL HttpResponse* http_response_new(void);
|
FREERDP_LOCAL HttpResponse* http_response_new(void);
|
||||||
FREERDP_LOCAL void http_response_free(HttpResponse* response);
|
FREERDP_LOCAL void http_response_free(HttpResponse* response);
|
||||||
|
|
||||||
FREERDP_LOCAL BOOL http_response_print(HttpResponse* response);
|
|
||||||
FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength);
|
FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength);
|
||||||
|
|
||||||
FREERDP_LOCAL long http_response_get_status_code(HttpResponse* response);
|
FREERDP_LOCAL long http_response_get_status_code(HttpResponse* response);
|
||||||
FREERDP_LOCAL SSIZE_T http_response_get_body_length(HttpResponse* response);
|
FREERDP_LOCAL size_t http_response_get_body_length(HttpResponse* response);
|
||||||
FREERDP_LOCAL const BYTE* http_response_get_body(HttpResponse* response);
|
FREERDP_LOCAL const BYTE* http_response_get_body(HttpResponse* response);
|
||||||
FREERDP_LOCAL const char* http_response_get_auth_token(HttpResponse* response, const char* method);
|
FREERDP_LOCAL const char* http_response_get_auth_token(HttpResponse* response, const char* method);
|
||||||
FREERDP_LOCAL const char* http_response_get_setcookie(HttpResponse* response, const char* cookie);
|
FREERDP_LOCAL const char* http_response_get_setcookie(HttpResponse* response, const char* cookie);
|
||||||
FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(HttpResponse* response);
|
FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(HttpResponse* response);
|
||||||
FREERDP_LOCAL BOOL http_response_is_websocket(HttpContext* http, HttpResponse* response);
|
FREERDP_LOCAL BOOL http_response_is_websocket(HttpContext* http, HttpResponse* response);
|
||||||
|
|
||||||
|
FREERDP_LOCAL void http_response_log_error_status(wLog* log, DWORD level, HttpResponse* response);
|
||||||
|
|
||||||
/* chunked read helper */
|
/* chunked read helper */
|
||||||
FREERDP_LOCAL int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size,
|
FREERDP_LOCAL int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size,
|
||||||
http_encoding_chunked_context* encodingContext);
|
http_encoding_chunked_context* encodingContext);
|
||||||
|
@ -720,8 +720,7 @@ static BOOL rdg_recv_auth_token(rdpCredsspAuth* auth, HttpResponse* response)
|
|||||||
case HTTP_STATUS_OK:
|
case HTTP_STATUS_OK:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WLog_WARN(TAG, "Unexpected HTTP status: %s",
|
http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response);
|
||||||
freerdp_http_status_string_format(StatusCode, buffer, ARRAYSIZE(buffer)));
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1303,11 +1302,6 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char*
|
|||||||
{
|
{
|
||||||
char buffer[64] = { 0 };
|
char buffer[64] = { 0 };
|
||||||
HttpResponse* response = NULL;
|
HttpResponse* response = NULL;
|
||||||
long statusCode;
|
|
||||||
SSIZE_T bodyLength;
|
|
||||||
long StatusCode;
|
|
||||||
TRANSFER_ENCODING encoding;
|
|
||||||
BOOL isWebsocket;
|
|
||||||
|
|
||||||
if (!rdg_tls_connect(rdg, tls, peerAddress, timeout))
|
if (!rdg_tls_connect(rdg, tls, peerAddress, timeout))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1333,7 +1327,7 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char*
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusCode = http_response_get_status_code(response);
|
const long StatusCode = http_response_get_status_code(response);
|
||||||
|
|
||||||
switch (StatusCode)
|
switch (StatusCode)
|
||||||
{
|
{
|
||||||
@ -1345,7 +1339,10 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char*
|
|||||||
http_response_free(response);
|
http_response_free(response);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
case HTTP_STATUS_OK:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1394,10 +1391,10 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statusCode = http_response_get_status_code(response);
|
const long statusCode = http_response_get_status_code(response);
|
||||||
bodyLength = http_response_get_body_length(response);
|
const size_t bodyLength = http_response_get_body_length(response);
|
||||||
encoding = http_response_get_transfer_encoding(response);
|
const TRANSFER_ENCODING encoding = http_response_get_transfer_encoding(response);
|
||||||
isWebsocket = http_response_is_websocket(rdg->http, response);
|
const BOOL isWebsocket = http_response_is_websocket(rdg->http, response);
|
||||||
http_response_free(response);
|
http_response_free(response);
|
||||||
WLog_DBG(TAG, "%s authorization result: %s", method,
|
WLog_DBG(TAG, "%s authorization result: %s", method,
|
||||||
freerdp_http_status_string_format(statusCode, buffer, ARRAYSIZE(buffer)));
|
freerdp_http_status_string_format(statusCode, buffer, ARRAYSIZE(buffer)));
|
||||||
@ -1442,8 +1439,7 @@ static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char*
|
|||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
default:
|
default:
|
||||||
WLog_WARN(TAG, "Unexpected HTTP status %s",
|
http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response);
|
||||||
freerdp_http_status_string_format(statusCode, buffer, ARRAYSIZE(buffer)));
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,11 +602,7 @@ static SSIZE_T rpc_client_default_out_channel_recv(rdpRpc* rpc)
|
|||||||
|
|
||||||
if (statusCode != HTTP_STATUS_OK)
|
if (statusCode != HTTP_STATUS_OK)
|
||||||
{
|
{
|
||||||
char buffer[64] = { 0 };
|
http_response_log_error_status(WLog_Get(TAG), WLOG_ERROR, response);
|
||||||
|
|
||||||
WLog_ERR(TAG, "error! Status Code: %s",
|
|
||||||
freerdp_http_status_string_format(statusCode, buffer, ARRAYSIZE(buffer)));
|
|
||||||
http_response_print(response);
|
|
||||||
|
|
||||||
if (statusCode == HTTP_STATUS_DENIED)
|
if (statusCode == HTTP_STATUS_DENIED)
|
||||||
{
|
{
|
||||||
|
@ -179,8 +179,7 @@ static BOOL wst_recv_auth_token(rdpCredsspAuth* auth, HttpResponse* response)
|
|||||||
case HTTP_STATUS_OK:
|
case HTTP_STATUS_OK:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WLog_WARN(TAG, "Unexpected HTTP status: %s",
|
http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response);
|
||||||
freerdp_http_status_string_format(StatusCode, buffer, ARRAYSIZE(buffer)));
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +480,9 @@ BOOL wst_connect(rdpWst* wst, DWORD timeout)
|
|||||||
|
|
||||||
case HTTP_STATUS_DENIED:
|
case HTTP_STATUS_DENIED:
|
||||||
success = wst_handle_denied(wst, &response, &StatusCode);
|
success = wst_handle_denied(wst, &response, &StatusCode);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user