Unverified Commit 614953be authored by Kip's avatar Kip Committed by GitHub

Merge pull request #957 from Tachi107/experimental-client

Move the Http client to `Pistache::Experimental`
parents 23b88dd0 10e205e8
...@@ -33,9 +33,9 @@ int main(int argc, char* argv[]) ...@@ -33,9 +33,9 @@ int main(int argc, char* argv[])
count = std::stoi(argv[2]); count = std::stoi(argv[2]);
} }
Http::Client client; Http::Experimental::Client client;
auto opts = Http::Client::options().threads(1).maxConnectionsPerHost(8); auto opts = Http::Experimental::Client::options().threads(1).maxConnectionsPerHost(8);
client.init(opts); client.init(opts);
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
namespace Pistache::Http namespace Pistache::Http::Experimental
{ {
namespace Default namespace Default
......
...@@ -168,13 +168,16 @@ namespace Pistache ...@@ -168,13 +168,16 @@ namespace Pistache
}; };
} // namespace Uri } // namespace Uri
// Remove when RequestBuilder will be out of namespace Experimental
namespace Experimental {class RequestBuilder; };
// 5. Request // 5. Request
class Request : public Message class Request : public Message
{ {
public: public:
friend class Private::RequestLineStep; friend class Private::RequestLineStep;
friend class RequestBuilder; friend class Experimental::RequestBuilder;
Request() = default; Request() = default;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
namespace Pistache::Http namespace Pistache::Http::Experimental
{ {
using NotifyOn = Polling::NotifyOn; using NotifyOn = Polling::NotifyOn;
......
...@@ -48,7 +48,7 @@ TEST(http_client_test, one_client_with_one_request_with_onecookie) ...@@ -48,7 +48,7 @@ TEST(http_client_test, one_client_with_one_request_with_onecookie)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -87,7 +87,7 @@ TEST(http_client_test, one_client_with_one_request_with_several_cookies) ...@@ -87,7 +87,7 @@ TEST(http_client_test, one_client_with_one_request_with_several_cookies)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
......
...@@ -101,7 +101,7 @@ TEST(http_client_test, one_client_with_one_request) ...@@ -101,7 +101,7 @@ TEST(http_client_test, one_client_with_one_request)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
auto rb = client.get(server_address); auto rb = client.get(server_address);
...@@ -138,7 +138,7 @@ TEST(http_client_test, one_client_with_multiple_requests) ...@@ -138,7 +138,7 @@ TEST(http_client_test, one_client_with_multiple_requests)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -184,11 +184,11 @@ TEST(http_client_test, multiple_clients_with_one_request) ...@@ -184,11 +184,11 @@ TEST(http_client_test, multiple_clients_with_one_request)
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
const int CLIENT_SIZE = 3; const int CLIENT_SIZE = 3;
Http::Client client1; Http::Experimental::Client client1;
client1.init(); client1.init();
Http::Client client2; Http::Experimental::Client client2;
client2.init(); client2.init();
Http::Client client3; Http::Experimental::Client client3;
client3.init(); client3.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -249,7 +249,7 @@ TEST(http_client_test, timeout_reject) ...@@ -249,7 +249,7 @@ TEST(http_client_test, timeout_reject)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
auto rb = client.get(server_address).timeout(std::chrono::milliseconds(1000)); auto rb = client.get(server_address).timeout(std::chrono::milliseconds(1000));
...@@ -284,8 +284,8 @@ TEST( ...@@ -284,8 +284,8 @@ TEST(
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
auto opts = Http::Client::options().maxConnectionsPerHost(1).threads(2); auto opts = Http::Experimental::Client::options().maxConnectionsPerHost(1).threads(2);
client.init(opts); client.init(opts);
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -333,8 +333,8 @@ TEST( ...@@ -333,8 +333,8 @@ TEST(
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
auto opts = Http::Client::options().maxConnectionsPerHost(2).threads(1); auto opts = Http::Experimental::Client::options().maxConnectionsPerHost(2).threads(1);
client.init(opts); client.init(opts);
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -380,7 +380,7 @@ TEST(http_client_test, test_client_timeout) ...@@ -380,7 +380,7 @@ TEST(http_client_test, test_client_timeout)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -441,7 +441,7 @@ TEST(http_client_test, client_sends_query) ...@@ -441,7 +441,7 @@ TEST(http_client_test, client_sends_query)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::string queryStr; std::string queryStr;
...@@ -513,8 +513,8 @@ TEST(http_client_test, client_get_large_content) ...@@ -513,8 +513,8 @@ TEST(http_client_test, client_get_large_content)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
auto opts = Http::Client::options().maxResponseSize(8192); auto opts = Http::Experimental::Client::options().maxResponseSize(8192);
client.init(opts); client.init(opts);
auto response = client.get(server_address).send(); auto response = client.get(server_address).send();
...@@ -554,8 +554,8 @@ TEST(http_client_test, client_do_not_get_large_content) ...@@ -554,8 +554,8 @@ TEST(http_client_test, client_do_not_get_large_content)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
std::cout << "Server address: " << server_address << "\n"; std::cout << "Server address: " << server_address << "\n";
Http::Client client; Http::Experimental::Client client;
auto opts = Http::Client::options().maxResponseSize(4096); auto opts = Http::Experimental::Client::options().maxResponseSize(4096);
client.init(opts); client.init(opts);
auto response = client.get(server_address).send(); auto response = client.get(server_address).send();
......
...@@ -194,7 +194,7 @@ struct PingHandler : public Http::Handler ...@@ -194,7 +194,7 @@ struct PingHandler : public Http::Handler
int clientLogicFunc(size_t response_size, const std::string& server_page, int clientLogicFunc(size_t response_size, const std::string& server_page,
int timeout_seconds, int wait_seconds) int timeout_seconds, int wait_seconds)
{ {
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
...@@ -401,7 +401,7 @@ TEST(http_server_test, server_with_static_file) ...@@ -401,7 +401,7 @@ TEST(http_server_test, server_with_static_file)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
LOGGER("test", "Server address: " << server_address); LOGGER("test", "Server address: " << server_address);
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
auto rb = client.get(server_address); auto rb = client.get(server_address);
auto response = rb.send(); auto response = rb.send();
...@@ -443,7 +443,7 @@ TEST(http_server_test, server_request_copies_address) ...@@ -443,7 +443,7 @@ TEST(http_server_test, server_request_copies_address)
const std::string server_address = "localhost:" + server.getPort().toString(); const std::string server_address = "localhost:" + server.getPort().toString();
LOGGER("test", "Server address: " << server_address); LOGGER("test", "Server address: " << server_address);
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
auto rb = client.get(server_address); auto rb = client.get(server_address);
auto response = rb.send(); auto response = rb.send();
...@@ -511,7 +511,7 @@ TEST(http_server_test, response_size_captured) ...@@ -511,7 +511,7 @@ TEST(http_server_test, response_size_captured)
// Use the built-in http client, but this test is interested in testing // Use the built-in http client, but this test is interested in testing
// that the ResponseWriter in the server stashed the correct size and code // that the ResponseWriter in the server stashed the correct size and code
// values. // values.
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
auto rb = client.get(server_address); auto rb = client.get(server_address);
auto response = rb.send(); auto response = rb.send();
......
...@@ -49,8 +49,8 @@ void testRequestSizes(const std::string& url, ...@@ -49,8 +49,8 @@ void testRequestSizes(const std::string& url,
RequestSizeTestSets testResults; RequestSizeTestSets testResults;
std::mutex resultsetMutex; std::mutex resultsetMutex;
Http::Client client; Http::Experimental::Client client;
auto client_opts = Http::Client::options().threads(3).maxConnectionsPerHost(3); auto client_opts = Http::Experimental::Client::options().threads(3).maxConnectionsPerHost(3);
client.init(client_opts); client.init(client_opts);
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
......
...@@ -40,7 +40,7 @@ struct HelloHandlerWithDelay : public Http::Handler ...@@ -40,7 +40,7 @@ struct HelloHandlerWithDelay : public Http::Handler
int clientLogicFunc(int response_size, const std::string& server_page, int clientLogicFunc(int response_size, const std::string& server_page,
int wait_seconds) int wait_seconds)
{ {
Http::Client client; Http::Experimental::Client client;
client.init(); client.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment