Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/net/http/client_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace http {
// Assume we want some headers
if(!header.is_empty())
{
// Note: Content Length is not required
if(header.has_field(header::Content_Length))
{
try
Expand All @@ -137,8 +138,15 @@ namespace http {
catch(...)
{ end_response({Error::INVALID}); }
}
else
// HTTP/1.1 7.2.2 Length: Any response message which must not include an entity body
// (such as the 1xx, 204, and 304 responses and any response to a HEAD request)
// is always terminated by the first empty line after the header fields
else if(const auto code = res_->status_code();
is_informational(code) or code == No_Content or code == Not_Modified
or req_->method() == HEAD)
{
end_response();
}
}
else if(req_->method() == HEAD)
{
Expand Down Expand Up @@ -228,7 +236,12 @@ namespace http {
auto callback = std::move(on_response_);
on_response_.reset();
timer_.stop();
callback(Error::CLOSING, std::move(res_), *this);
if(res_ != nullptr and res_->headers_complete()) {
callback(Error::NONE, std::move(res_), *this);
}
else {
callback(Error::CLOSING, std::move(res_), *this);
}
}

client_.close(*this);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ set(TEST_LIST
#gateway disabled as it needs nacl.. circular DEP issue
#"gateway" "50" "net"
#TODO move http to http library
#"http" "20" "net"
"http" "20" "net"
"icmp" "50" "net"
"icmp6" "50" "net"
#TODO move to microlb with framework to test
Expand Down
2 changes: 1 addition & 1 deletion test/net/integration/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
#service
project (service)

Expand Down
54 changes: 13 additions & 41 deletions test/net/integration/http/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ void Service::ready()
printf("Sending request:\n%s\n", req.to_string().c_str());
});

INFO("Basic_client", "HTTPS");

try
{
client_->get("https://www.google.com", {}, [](Error err, Response_ptr res, Connection&) {});
assert(false && "Basic Client should throw exception");
}
catch(const http::Client_error& err)
{
CHECKSERT(true, "Basic Client should throw exception on https URL");
}

INFO("Basic_client", "Testing against local server");

auto req = client_->create_request();
Expand All @@ -79,47 +91,7 @@ void Service::ready()
printf("Received body: %s\n", res->body());
CHECKSERT(res->body() == "/testing", "Received body: \"/testing\"");

using namespace std::chrono; // zzz...
Timers::oneshot(5s, [](auto) { printf("SUCCESS\n"); });
printf("SUCCESS\n");
});


INFO("Basic_client", "Testing against Acorn");

const std::string acorn_url{"http://acorn2.unofficial.includeos.io/"};

client_->get(acorn_url, {},
[] (Error err, Response_ptr res, Connection&)
{
CHECK(!err, "Error: %s", err.to_string().c_str());
CHECK(res != nullptr, "Received response");
if(!err)
printf("Response:\n%s\n", res->to_string().c_str());
});

using namespace std::chrono;
Basic_client::Options options;
options.timeout = 3s;
client_->get(acorn_url + "api/dashboard/status", {},
[] (Error err, Response_ptr res, Connection&)
{
CHECK(!err, "Error: %s", err.to_string().c_str());
CHECK(res != nullptr, "Received response");
if(!err)
printf("Response:\n%s\n", res->to_string().c_str());
}, options);


INFO("Basic_client", "HTTPS");

try
{
client_->get("https://www.google.com", {}, [](Error err, Response_ptr res, Connection&) {});
assert(false && "Basic Client should throw exception");
}
catch(const http::Client_error& err)
{
CHECKSERT(true, "Basic Client should throw exception on https URL");
}

}
2 changes: 1 addition & 1 deletion test/net/integration/http/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def Client_test():
import urllib.request, urllib.error, urllib.parse
def Server_test(triggerline):
res = urllib.request.urlopen("http://10.0.0.46:8080").read()
assert(res == "Hello")
assert(res.decode('utf-8') == "Hello")


# Get an auto-created VM from the vmrunner
Expand Down