diff options
author | Mattes D <github@xoft.cz> | 2023-05-11 22:05:17 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2023-05-16 23:50:37 +0200 |
commit | c9522fb740200ccef6230cec452c48efb31e5394 (patch) | |
tree | 7e74d70699e13dd0a92444a1a0add7a3059ac7ca /src/HTTP | |
parent | Try a timeout for jobs. (diff) | |
download | cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.gz cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.bz2 cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.lz cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.xz cuberite-c9522fb740200ccef6230cec452c48efb31e5394.tar.zst cuberite-c9522fb740200ccef6230cec452c48efb31e5394.zip |
Diffstat (limited to 'src/HTTP')
-rw-r--r-- | src/HTTP/HTTPMessageParser.cpp | 4 | ||||
-rw-r--r-- | src/HTTP/HTTPServerConnection.cpp | 6 | ||||
-rw-r--r-- | src/HTTP/TransferEncodingParser.cpp | 14 | ||||
-rw-r--r-- | src/HTTP/UrlClient.cpp | 24 | ||||
-rw-r--r-- | src/HTTP/UrlParser.cpp | 2 |
5 files changed, 25 insertions, 25 deletions
diff --git a/src/HTTP/HTTPMessageParser.cpp b/src/HTTP/HTTPMessageParser.cpp index 18d2968b5..de3cf6518 100644 --- a/src/HTTP/HTTPMessageParser.cpp +++ b/src/HTTP/HTTPMessageParser.cpp @@ -162,7 +162,7 @@ void cHTTPMessageParser::HeadersFinished(void) m_TransferEncodingParser = cTransferEncodingParser::Create(*this, m_TransferEncoding, m_ContentLength); if (m_TransferEncodingParser == nullptr) { - OnError(Printf("Unknown transfer encoding: %s", m_TransferEncoding.c_str())); + OnError(fmt::format(FMT_STRING("Unknown transfer encoding: {}"), m_TransferEncoding)); return; } } @@ -179,7 +179,7 @@ void cHTTPMessageParser::OnHeaderLine(const AString & a_Key, const AString & a_V { if (!StringToInteger(a_Value, m_ContentLength)) { - OnError(Printf("Invalid content length header value: \"%s\"", a_Value.c_str())); + OnError(fmt::format(FMT_STRING("Invalid content length header value: \"{}\""), a_Value)); } return; } diff --git a/src/HTTP/HTTPServerConnection.cpp b/src/HTTP/HTTPServerConnection.cpp index df9c0970a..f79f08517 100644 --- a/src/HTTP/HTTPServerConnection.cpp +++ b/src/HTTP/HTTPServerConnection.cpp @@ -30,8 +30,8 @@ cHTTPServerConnection::~cHTTPServerConnection() = default; void cHTTPServerConnection::SendStatusAndReason(int a_StatusCode, const AString & a_Response) { - SendData(Printf("HTTP/1.1 %d %s\r\n", a_StatusCode, a_Response.c_str())); - SendData(Printf("Content-Length: %u\r\n\r\n", static_cast<unsigned>(a_Response.size()))); + SendData(fmt::format(FMT_STRING("HTTP/1.1 {} {}\r\n"), a_StatusCode, a_Response)); + SendData(fmt::format(FMT_STRING("Content-Length: {}\r\n\r\n"), a_Response)); SendData(a_Response.data(), a_Response.size()); m_CurrentRequest.reset(); m_Parser.Reset(); @@ -43,7 +43,7 @@ void cHTTPServerConnection::SendStatusAndReason(int a_StatusCode, const AString void cHTTPServerConnection::SendNeedAuth(const AString & a_Realm) { - SendData(Printf("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"%s\"\r\nContent-Length: 0\r\n\r\n", a_Realm.c_str())); + SendData(fmt::format(FMT_STRING("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"{}\"\r\nContent-Length: 0\r\n\r\n"), a_Realm)); m_CurrentRequest.reset(); m_Parser.Reset(); } diff --git a/src/HTTP/TransferEncodingParser.cpp b/src/HTTP/TransferEncodingParser.cpp index 98d870460..925c919d3 100644 --- a/src/HTTP/TransferEncodingParser.cpp +++ b/src/HTTP/TransferEncodingParser.cpp @@ -120,7 +120,7 @@ protected: } default: { - Error(Printf("Invalid character in chunk length line: 0x%x", a_Data[i])); + Error(fmt::format(FMT_STRING("Invalid character in chunk length line: 0x{:02x}"), a_Data[i])); return AString::npos; } } // switch (a_Data[i]) @@ -150,7 +150,7 @@ protected: if (a_Data[i] < 32) { // Only printable characters are allowed in the trailer - Error(Printf("Invalid character in chunk length line: 0x%x", a_Data[i])); + Error(fmt::format(FMT_STRING("Invalid character in chunk length line: 0x{:02x}"), a_Data[i])); return AString::npos; } } @@ -183,7 +183,7 @@ protected: } return 1; } - Error(Printf("Invalid character past chunk length's CR: 0x%x", a_Data[0])); + Error(fmt::format(FMT_STRING("Invalid character past chunk length's CR: 0x{:02x}"), a_Data[0])); return AString::npos; } @@ -219,7 +219,7 @@ protected: m_State = psChunkDataLF; return 1; } - Error(Printf("Invalid character past chunk data: 0x%x", a_Data[0])); + Error(fmt::format(FMT_STRING("Invalid character past chunk data: 0x{:02x}"), a_Data[0])); return AString::npos; } @@ -241,7 +241,7 @@ protected: m_State = psChunkLength; return 1; } - Error(Printf("Invalid character past chunk data's CR: 0x%x", a_Data[0])); + Error(fmt::format(FMT_STRING("Invalid character past chunk data's CR: 0x{:02x}"), a_Data[0])); return AString::npos; } @@ -292,11 +292,11 @@ protected: return a_Size; } - virtual void Finish(void) override + virtual void Finish() override { if (m_State != psFinished) { - Error(Printf("ChunkedTransferEncoding: Finish signal received before the data stream ended (state: %d)", m_State)); + Error(fmt::format(FMT_STRING("ChunkedTransferEncoding: Finish signal received before the data stream ended (state: {})"), m_State)); } m_State = psFinished; } diff --git a/src/HTTP/UrlClient.cpp b/src/HTTP/UrlClient.cpp index 315856f69..13a882205 100644 --- a/src/HTTP/UrlClient.cpp +++ b/src/HTTP/UrlClient.cpp @@ -168,7 +168,7 @@ protected: // cNetwork::cConnectCallbacks override: An error has occurred: virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override { - m_Callbacks->OnError(Printf("Network error %d (%s)", a_ErrorCode, a_ErrorMsg.c_str())); + m_Callbacks->OnError(fmt::format(FMT_STRING("Network error {} ({})"), a_ErrorCode, a_ErrorMsg)); } @@ -285,14 +285,14 @@ public: requestLine.push_back('?'); requestLine.append(m_ParentRequest.m_UrlQuery); } - m_Link->Send(Printf("%s %s HTTP/1.1\r\n", m_ParentRequest.m_Method.c_str(), requestLine.c_str())); + m_Link->Send(fmt::format(FMT_STRING("{} {} HTTP/1.1\r\n"), m_ParentRequest.m_Method, requestLine)); // Send the headers: - m_Link->Send(Printf("Host: %s\r\n", m_ParentRequest.m_UrlHost.c_str())); - m_Link->Send(Printf("Content-Length: %u\r\n", static_cast<unsigned>(m_ParentRequest.m_Body.size()))); - for (auto itr = m_ParentRequest.m_Headers.cbegin(), end = m_ParentRequest.m_Headers.cend(); itr != end; ++itr) + m_Link->Send(fmt::format(FMT_STRING("Host: {}\r\n"), m_ParentRequest.m_UrlHost)); + m_Link->Send(fmt::format(FMT_STRING("Content-Length: {}\r\n"), m_ParentRequest.m_Body)); + for (const auto & hdr: m_ParentRequest.m_Headers) { - m_Link->Send(Printf("%s: %s\r\n", itr->first.c_str(), itr->second.c_str())); + m_Link->Send(fmt::format(FMT_STRING("{}: {}\r\n"), hdr.first, hdr.second)); } // for itr - m_Headers[] m_Link->Send("\r\n", 2); @@ -341,20 +341,20 @@ public: auto idxFirstSpace = a_FirstLine.find(' '); if (idxFirstSpace == AString::npos) { - m_ParentRequest.CallErrorCallback(Printf("Failed to parse HTTP status line \"%s\", no space delimiter.", a_FirstLine.c_str())); + m_ParentRequest.CallErrorCallback(fmt::format(FMT_STRING("Failed to parse HTTP status line \"{}\", no space delimiter."), a_FirstLine)); return; } auto idxSecondSpace = a_FirstLine.find(' ', idxFirstSpace + 1); if (idxSecondSpace == AString::npos) { - m_ParentRequest.CallErrorCallback(Printf("Failed to parse HTTP status line \"%s\", missing second space delimiter.", a_FirstLine.c_str())); + m_ParentRequest.CallErrorCallback(fmt::format(FMT_STRING("Failed to parse HTTP status line \"{}\", missing second space delimiter."), a_FirstLine)); return; } int resultCode; auto resultCodeStr = a_FirstLine.substr(idxFirstSpace + 1, idxSecondSpace - idxFirstSpace - 1); if (!StringToInteger(resultCodeStr, resultCode)) { - m_ParentRequest.CallErrorCallback(Printf("Failed to parse HTTP result code from response \"%s\"", resultCodeStr.c_str())); + m_ParentRequest.CallErrorCallback(fmt::format(FMT_STRING("Failed to parse HTTP result code from response \"{}\""), resultCodeStr)); return; } @@ -489,7 +489,7 @@ void cUrlClientRequest::RedirectTo(const AString & a_RedirectUrl) m_Callbacks->OnRedirecting(a_RedirectUrl); if (!ShouldAllowRedirects()) { - CallErrorCallback(Printf("Redirect to \"%s\" not allowed", a_RedirectUrl.c_str())); + CallErrorCallback(fmt::format(FMT_STRING("Redirect to \"{}\" not allowed"), a_RedirectUrl)); return; } @@ -507,7 +507,7 @@ void cUrlClientRequest::RedirectTo(const AString & a_RedirectUrl) auto res = DoRequest(Self); if (!res.first) { - m_Callbacks->OnError(Printf("Redirection failed: %s", res.second.c_str())); + m_Callbacks->OnError(fmt::format(FMT_STRING("Redirection failed: {}"), res.second)); } } @@ -590,7 +590,7 @@ std::pair<bool, AString> cUrlClientRequest::DoRequest(const std::shared_ptr<cUrl m_SchemeHandler = cSchemeHandler::Create(m_UrlScheme, *this); if (m_SchemeHandler == nullptr) { - return std::make_pair(false, Printf("Unknown Url scheme: %s", m_UrlScheme.c_str())); + return std::make_pair(false, fmt::format(FMT_STRING("Unknown URL scheme: {}"), m_UrlScheme)); } // Connect and transfer ownership to the link diff --git a/src/HTTP/UrlParser.cpp b/src/HTTP/UrlParser.cpp index 05db3e413..85b1cd216 100644 --- a/src/HTTP/UrlParser.cpp +++ b/src/HTTP/UrlParser.cpp @@ -135,7 +135,7 @@ std::pair<bool, AString> cUrlParser::Parse( a_Port = GetDefaultPort(a_Scheme); if (a_Port == 0) { - return std::make_pair(false, Printf("Unknown URL scheme: \"%s\"", a_Scheme.c_str())); + return std::make_pair(false, fmt::format(FMT_STRING("Unknown URL scheme: \"{}\""), a_Scheme)); } // If the next two chars are a double-slash, skip them: |