summaryrefslogtreecommitdiff
path: root/zen/http.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-04-18 12:59:51 -0400
committerB Stack <bgstack15@gmail.com>2020-04-18 12:59:51 -0400
commitfc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0 (patch)
tree8cfcea5441be72ad92095a3887ded84d38f9ba11 /zen/http.cpp
parentMerge branch '10.22' into 'master' (diff)
downloadFreeFileSync-fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0.tar.gz
FreeFileSync-fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0.tar.bz2
FreeFileSync-fc8cd27e4c0c8a48ebc151f73639a573e9e5c7f0.zip
add upstream 10.23
Diffstat (limited to 'zen/http.cpp')
-rw-r--r--zen/http.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/zen/http.cpp b/zen/http.cpp
index c6a390de..848b2cb3 100644
--- a/zen/http.cpp
+++ b/zen/http.cpp
@@ -59,7 +59,7 @@ public:
else //HTTP default port: 80, see %WINDIR%\system32\drivers\etc\services
socket_ = std::make_unique<Socket>(server, Zstr("http")); //throw SysError
- //we don't support "chunked and gzip transfer encoding" => HTTP 1.0
+ //we don't support "chunked and gzip transfer encoding" => HTTP 1.0 => no "Content-Length" support!
headers["Host" ] = utfTo<std::string>(server); //only required for HTTP/1.1 but a few servers expect it even for HTTP/1.0
headers["User-Agent"] = utfTo<std::string>(userAgent);
headers["Accept" ] = "*/*"; //won't hurt?
@@ -194,7 +194,8 @@ private:
contentRemaining_ -= bytesReceived;
if (bytesReceived == 0 && contentRemaining_ > 0)
- throw SysError(replaceCpy<std::wstring>(L"HttpInputStream::tryRead: incomplete server response; %x more bytes expected.", L"%x", numberTo<std::wstring>(contentRemaining_)));
+ throw SysError(formatSystemError("HttpInputStream::tryRead", L"", L"Incomplete server response: " +
+ numberTo<std::wstring>(contentRemaining_) + L" more bytes expected."));
return bytesReceived; //"zero indicates end of file"
}
@@ -259,8 +260,8 @@ std::unique_ptr<HttpInputStream::Impl> sendHttpRequestImpl(const Zstring& url,
}
else
{
- if (httpStatus != 200) //HTTP_STATUS_OK(200)
- throw SysError(formatHttpStatus(httpStatus)); //e.g. HTTP_STATUS_NOT_FOUND(404)
+ if (httpStatus != 200) //HTTP_STATUS_OK
+ throw SysError(formatHttpError(httpStatus)); //e.g. "HTTP status 404: Not found."
return response;
}
@@ -380,9 +381,9 @@ bool zen::internetIsAlive() //noexcept
}
-std::wstring zen::formatHttpStatus(int sc)
+std::wstring zen::formatHttpError(int sc)
{
- const wchar_t* statusText = [&] //https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
+ const wchar_t* statusDescr = [&] //https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
{
switch (sc)
{
@@ -455,10 +456,7 @@ std::wstring zen::formatHttpStatus(int sc)
}
}();
- if (strLength(statusText) == 0)
- return trimCpy(replaceCpy<std::wstring>(L"HTTP status %x.", L"%x", numberTo<std::wstring>(sc)));
- else
- return trimCpy(replaceCpy<std::wstring>(L"HTTP status %x: ", L"%x", numberTo<std::wstring>(sc)) + statusText);
+ return formatSystemError("", L"HTTP status " + numberTo<std::wstring>(sc), statusDescr);
}
bgstack15