diff options
| author | Michał Cichoń <michcic@gmail.com> | 2017-05-17 04:07:07 +0200 | 
|---|---|---|
| committer | Michał Cichoń <michcic@gmail.com> | 2017-05-17 04:37:39 +0200 | 
| commit | 817ff6a87020a55d7628d600e2ee09b947ee2f4e (patch) | |
| tree | be90eee756de623bccfd3c4cd603c71ec6f0ac2f /src/http | |
| parent | 7c4b615a38a49e1bbe9c2315fed09920aa238b65 (diff) | |
| download | pianobar-windows-817ff6a87020a55d7628d600e2ee09b947ee2f4e.tar.gz pianobar-windows-817ff6a87020a55d7628d600e2ee09b947ee2f4e.tar.bz2 pianobar-windows-817ff6a87020a55d7628d600e2ee09b947ee2f4e.zip  | |
Show status code text if no other source of error is available.
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/http.c | 21 | 
1 files changed, 20 insertions, 1 deletions
diff --git a/src/http/http.c b/src/http/http.c index dd64ad1..609317f 100644 --- a/src/http/http.c +++ b/src/http/http.c @@ -44,6 +44,7 @@ static wchar_t* HttpToWideString(const char* string, int size);  static bool HttpCreateConnection (http_t http);  static void HttpCloseConnection (http_t http);  static void HttpSetLastError (http_t http, const char* message); +static void HttpSetLastErrorW (http_t http, const wchar_t* message);  static void HttpSetLastErrorFromWinHttp (http_t http);  static char* HttpFormatWinApiError (DWORD errorCode, HINSTANCE module);  static char* HttpFormatWinHttpError (DWORD errorCode); @@ -118,11 +119,19 @@ static void HttpCloseConnection (http_t http) {  static void HttpSetLastError (http_t http, const char* message) {  	free(http->error);  	http->error = NULL; -	 +  	if (message)  		http->error = strdup(message);  } +static void HttpSetLastErrorW (http_t http, const wchar_t* message) { +	free(http->error); +	http->error = NULL; + +	if (message) +		http->error = HttpToString(message, wcslen(message)); +} +  static void HttpSetLastErrorFromWinHttp (http_t http) {  	free(http->error);  	http->error = NULL; @@ -396,6 +405,13 @@ bool HttpRequest(http_t http, PianoRequest_t * const request) {  		}  		if (succeeded && statusCode == 407) { +			wchar_t statusText[256] = { 0 }; +			DWORD statusTextSize = sizeof(statusText) - 1; +			WinHttpQueryHeaders(handle, +				WINHTTP_QUERY_STATUS_TEXT, +				WINHTTP_HEADER_NAME_BY_INDEX, +				statusText, &statusTextSize, WINHTTP_NO_HEADER_INDEX); +			HttpSetLastErrorW (http, statusText);  			requestSent = false;  			retry       = true;  		} @@ -467,6 +483,9 @@ bool HttpRequest(http_t http, PianoRequest_t * const request) {  			HttpSetLastError (http, "Maximum retries count exceeded");  	} +	if (retryLimit == 0) +		goto done; +  	complete = true;  	HttpSetLastError (http, NULL);  | 
