Browse Source

fixed test-http-req

pull/1862/head
orignal 2 years ago
parent
commit
8a106eb09e
  1. 10
      libi2pd/HTTP.cpp
  2. 4
      libi2pd/HTTP.h
  3. 30
      tests/test-http-req.cpp

10
libi2pd/HTTP.cpp

@ -1,5 +1,5 @@ @@ -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
*
@ -350,6 +350,14 @@ namespace http @@ -350,6 +350,14 @@ namespace http
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
{
auto it = headers.find("Transfer-Encoding");

4
libi2pd/HTTP.h

@ -1,5 +1,5 @@ @@ -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
*
@ -102,6 +102,8 @@ namespace http @@ -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) { RemoveHeader (name, ""); };
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 {

30
tests/test-http-req.cpp

@ -22,13 +22,13 @@ int main() { @@ -22,13 +22,13 @@ int main() {
assert(req->version == "HTTP/1.0");
assert(req->method == "GET");
assert(req->uri == "/");
assert(req->headers.size() == 3);
assert(req->headers.count("Host") == 1);
assert(req->headers.count("Accept") == 1);
assert(req->headers.count("User-Agent") == 1);
assert(req->headers.find("Host")->second == "inr.i2p");
assert(req->headers.find("Accept")->second == "*/*");
assert(req->headers.find("User-Agent")->second == "curl/7.26.0");
assert(req->GetNumHeaders () == 3);
assert(req->GetNumHeaders("Host") == 1);
assert(req->GetNumHeaders("Accept") == 1);
assert(req->GetNumHeaders("User-Agent") == 1);
assert(req->GetHeader("Host") == "inr.i2p");
assert(req->GetHeader("Accept") == "*/*");
assert(req->GetHeader("User-Agent") == "curl/7.26.0");
delete req;
/* test: parsing request without body */
@ -41,7 +41,7 @@ int main() { @@ -41,7 +41,7 @@ int main() {
assert(req->version == "HTTP/1.0");
assert(req->method == "GET");
assert(req->uri == "/");
assert(req->headers.size() == 0);
assert(req->GetNumHeaders () == 0);
delete req;
/* test: parsing request without body */
@ -74,13 +74,13 @@ int main() { @@ -74,13 +74,13 @@ int main() {
assert((ret = req->parse(buf, len)) == len); /* no host header */
assert(req->method == "GET");
assert(req->uri == "http://inr.i2p");
assert(req->headers.size() == 3);
assert(req->headers.count("Host") == 1);
assert(req->headers.count("Accept") == 1);
assert(req->headers.count("Accept-Encoding") == 1);
assert(req->headers["Host"] == "stats.i2p");
assert(req->headers["Accept"] == "*/*");
assert(req->headers["Accept-Encoding"] == "");
assert(req->GetNumHeaders () == 3);
assert(req->GetNumHeaders("Host") == 1);
assert(req->GetNumHeaders("Accept") == 1);
assert(req->GetNumHeaders("Accept-Encoding") == 1);
assert(req->GetHeader("Host") == "stats.i2p");
assert(req->GetHeader("Accept") == "*/*");
assert(req->GetHeader("Accept-Encoding") == "");
delete req;
return 0;

Loading…
Cancel
Save