mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-09 15:50:26 +03:00
fixed test-http-req
This commit is contained in:
parent
f9331897b8
commit
8a106eb09e
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2022, The PurpleI2P Project
|
* Copyright (c) 2013-2023, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -350,6 +350,14 @@ namespace http
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t HTTPReq::GetNumHeaders (const std::string& name) const
|
||||||
|
{
|
||||||
|
size_t num = 0;
|
||||||
|
for (auto& it : headers)
|
||||||
|
if (it.first == name) num++;
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
bool HTTPRes::is_chunked() const
|
bool HTTPRes::is_chunked() const
|
||||||
{
|
{
|
||||||
auto it = headers.find("Transfer-Encoding");
|
auto it = headers.find("Transfer-Encoding");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2021, The PurpleI2P Project
|
* Copyright (c) 2013-2023, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -102,6 +102,8 @@ namespace http
|
|||||||
void RemoveHeader (const std::string& name, const std::string& exempt); // remove all headers starting with name, but exempt
|
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, ""); };
|
void RemoveHeader (const std::string& name) { RemoveHeader (name, ""); };
|
||||||
std::string GetHeader (const std::string& name) const;
|
std::string GetHeader (const std::string& name) const;
|
||||||
|
size_t GetNumHeaders (const std::string& name) const;
|
||||||
|
size_t GetNumHeaders () const { return headers.size (); };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HTTPRes : HTTPMsg {
|
struct HTTPRes : HTTPMsg {
|
||||||
|
@ -22,13 +22,13 @@ int main() {
|
|||||||
assert(req->version == "HTTP/1.0");
|
assert(req->version == "HTTP/1.0");
|
||||||
assert(req->method == "GET");
|
assert(req->method == "GET");
|
||||||
assert(req->uri == "/");
|
assert(req->uri == "/");
|
||||||
assert(req->headers.size() == 3);
|
assert(req->GetNumHeaders () == 3);
|
||||||
assert(req->headers.count("Host") == 1);
|
assert(req->GetNumHeaders("Host") == 1);
|
||||||
assert(req->headers.count("Accept") == 1);
|
assert(req->GetNumHeaders("Accept") == 1);
|
||||||
assert(req->headers.count("User-Agent") == 1);
|
assert(req->GetNumHeaders("User-Agent") == 1);
|
||||||
assert(req->headers.find("Host")->second == "inr.i2p");
|
assert(req->GetHeader("Host") == "inr.i2p");
|
||||||
assert(req->headers.find("Accept")->second == "*/*");
|
assert(req->GetHeader("Accept") == "*/*");
|
||||||
assert(req->headers.find("User-Agent")->second == "curl/7.26.0");
|
assert(req->GetHeader("User-Agent") == "curl/7.26.0");
|
||||||
delete req;
|
delete req;
|
||||||
|
|
||||||
/* test: parsing request without body */
|
/* test: parsing request without body */
|
||||||
@ -41,7 +41,7 @@ int main() {
|
|||||||
assert(req->version == "HTTP/1.0");
|
assert(req->version == "HTTP/1.0");
|
||||||
assert(req->method == "GET");
|
assert(req->method == "GET");
|
||||||
assert(req->uri == "/");
|
assert(req->uri == "/");
|
||||||
assert(req->headers.size() == 0);
|
assert(req->GetNumHeaders () == 0);
|
||||||
delete req;
|
delete req;
|
||||||
|
|
||||||
/* test: parsing request without body */
|
/* test: parsing request without body */
|
||||||
@ -74,13 +74,13 @@ int main() {
|
|||||||
assert((ret = req->parse(buf, len)) == len); /* no host header */
|
assert((ret = req->parse(buf, len)) == len); /* no host header */
|
||||||
assert(req->method == "GET");
|
assert(req->method == "GET");
|
||||||
assert(req->uri == "http://inr.i2p");
|
assert(req->uri == "http://inr.i2p");
|
||||||
assert(req->headers.size() == 3);
|
assert(req->GetNumHeaders () == 3);
|
||||||
assert(req->headers.count("Host") == 1);
|
assert(req->GetNumHeaders("Host") == 1);
|
||||||
assert(req->headers.count("Accept") == 1);
|
assert(req->GetNumHeaders("Accept") == 1);
|
||||||
assert(req->headers.count("Accept-Encoding") == 1);
|
assert(req->GetNumHeaders("Accept-Encoding") == 1);
|
||||||
assert(req->headers["Host"] == "stats.i2p");
|
assert(req->GetHeader("Host") == "stats.i2p");
|
||||||
assert(req->headers["Accept"] == "*/*");
|
assert(req->GetHeader("Accept") == "*/*");
|
||||||
assert(req->headers["Accept-Encoding"] == "");
|
assert(req->GetHeader("Accept-Encoding") == "");
|
||||||
delete req;
|
delete req;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user