replace more strings to string_view
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions

This commit is contained in:
orignal 2025-03-15 16:43:08 -04:00
parent 67ab4fef6d
commit 960a85e415
2 changed files with 16 additions and 15 deletions

View file

@ -10,7 +10,6 @@
#include <utility>
#include <stdio.h>
#include <ctime>
#include <string_view>
#include <charconv>
#include "util.h"
#include "Base.h"
@ -334,11 +333,11 @@ namespace http
else
return -1;
}
pos = eol + strlen(CRLF);
pos = eol + CRLF.length();
if (pos >= eoh)
break;
}
return eoh + strlen(HTTP_EOH);
return eoh + HTTP_EOH.length();
}
void HTTPReq::write(std::ostream & o)
@ -382,7 +381,7 @@ namespace http
}
}
std::string HTTPReq::GetHeader (const std::string& name) const
std::string HTTPReq::GetHeader (std::string_view name) const
{
for (auto& it : headers)
if (it.first == name)
@ -390,7 +389,7 @@ namespace http
return "";
}
size_t HTTPReq::GetNumHeaders (const std::string& name) const
size_t HTTPReq::GetNumHeaders (std::string_view name) const
{
size_t num = 0;
for (auto& it : headers)
@ -477,11 +476,11 @@ namespace http
else
return -1;
}
pos = eol + strlen(CRLF);
pos = eol + CRLF.length();
if (pos >= eoh)
break;
}
return eoh + strlen(HTTP_EOH);
return eoh + HTTP_EOH.length();
}
std::string HTTPRes::to_string() {
@ -506,9 +505,11 @@ namespace http
return ss.str();
}
const char * HTTPCodeToStatus(int code) {
const char *ptr;
switch (code) {
std::string_view HTTPCodeToStatus(int code)
{
std::string_view ptr;
switch (code)
{
case 105: ptr = "Name Not Resolved"; break;
/* success */
case 200: ptr = "OK"; break;

View file

@ -21,8 +21,8 @@ namespace i2p
{
namespace http
{
const char CRLF[] = "\r\n"; /**< HTTP line terminator */
const char HTTP_EOH[] = "\r\n\r\n"; /**< HTTP end-of-headers mark */
constexpr std::string_view CRLF = "\r\n"; /**< HTTP line terminator */
constexpr std::string_view HTTP_EOH = "\r\n\r\n"; /**< HTTP end-of-headers mark */
struct URL
{
@ -101,8 +101,8 @@ namespace http
void UpdateHeader (const std::string& name, const std::string& value);
void RemoveHeader (const std::string& name, const std::string& exempt); // remove all headers starting with name, but exempt
void RemoveHeader (const std::string& name) { RemoveHeader (name, ""); };
std::string GetHeader (const std::string& name) const;
size_t GetNumHeaders (const std::string& name) const;
std::string GetHeader (std::string_view name) const;
size_t GetNumHeaders (std::string_view name) const;
size_t GetNumHeaders () const { return headers.size (); };
};
@ -152,7 +152,7 @@ namespace http
* @param code HTTP code [100, 599]
* @return Immutable string with status
*/
const char * HTTPCodeToStatus(int code);
std::string_view HTTPCodeToStatus(int code);
/**
* @brief Replaces %-encoded characters in string with their values