From f8d5ee463c9367595c4ca3f81236c9574f0b4524 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 18:37:27 +0530 Subject: [PATCH 01/20] first commit --- .../opentelemetry/sdk/common/http_client.h | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/common/http_client.h diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h new file mode 100644 index 0000000000..82effcbbad --- /dev/null +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -0,0 +1,128 @@ +#pragma once + +#include "opentelemetry/version.h" +#include "opentelemetry/nostd/function_ref.h" +#include +#include +#include + +// Usage Example +// +// struct ReponseHandler: public HttpResponseHandler { +// void OnHttpResponse(HttpResponse& res) noexcept override +// { +// if (res.IsSuccess()) +// .. process response +// } +// }; +// +// HttpSessionManager sessiionManager; // = getStaticInstance(); +// auto session = sessionManager.createHttpSession("localhost", 8000); +// auto request = session->CreateRequest(); +// request->AddHeader(..); +// ResponseHandler res_handler; +// session->SendRequest(res_handler); +// session->FinishSession() // optionally in the end. +// +// + + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace common +{ +namespace http +{ + +enum class HttpMethod { + HTTP_GET, + HTTP_POST, + HTTP_PUT, + HTTP_OPTIONS, + HTTP_HEAD, + HTTP_PATCH, + HTTP_DELETE +}; + +enum class HttpSessionState { + CREATED, //session object is created + ONGOING, // http(s) request is ongoing + FINISHED // https(s) reuest is finished +}; + +using HttpHeader = std::pair; +using HttpBody = std::vector; +using HttpStatusCode = uint16_t; + +class HttpRequest +{ + + public: + + virtual void setMethod(HttpMethod method) noexcept = 0; + + virtual void setURI(const std::string& uri) noexcept = 0; + + virtual void SetBody( HttpBody& body ) noexcept = 0; + + virtual void AddHeader(const HttpHeader& header) noexcept = 0; + + virtual void ReplaceHeader(const HttpHeader& header) noexcept = 0; + + virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; + +}; + +class HttpResponse +{ + public: + virtual const HttpBody& GetBody() const noexcept = 0; + + virtual bool GetNextHeader(nostd::function_ref callable ) const noexcept = 0; + + virtual bool GetNextHeader( const std::string& key, nostd::function_ref callable ) const noexcept = 0; + + virtual HttpStatusCode GetStatusCode() const noexcept = 0; + + virtual bool IsSuccess() const noexcept = 0; + + virtual const std::string& GetErrorMessage() const noexcept = 0; + +}; + +class HttpResponseHandler { + + public: + virtual void OnHttpResponse(HttpResponse&) noexcept = 0; +}; + +class HttpSession { + + public: + virtual std::shared_ptr CreateRequest() noexcept = 0; + + virtual void SendRequest(HttpResponseHandler&) noexcept = 0; + + virtual HttpSessionState GetSessionState() const noexcept = 0; + + virtual bool CancelSession() noexcept = 0; + + virtual bool FinishSession() noexcept = 0; + +}; + +class HttpSessionManager { + + public: + virtual std::shared_ptr createHttpSession(std::string host, uint16_t port = 80) noexcept = 0 ; + + virtual bool CancelAllSessions() noexcept = 0; + + virtual bool FinishAllSessions() noexcept = 0; + +}; +} //http +} //common +} //sdk +OPENTELEMETRY_END_NAMESPACE From ec891f1980c7f2678afd4613bce774962819dc35 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 18:40:49 +0530 Subject: [PATCH 02/20] format --- .../opentelemetry/sdk/common/http_client.h | 121 +++++++++--------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 82effcbbad..fea0fb9ac6 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -1,21 +1,21 @@ #pragma once -#include "opentelemetry/version.h" -#include "opentelemetry/nostd/function_ref.h" -#include -#include #include +#include +#include +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/version.h" // Usage Example // // struct ReponseHandler: public HttpResponseHandler { // void OnHttpResponse(HttpResponse& res) noexcept override -// { -// if (res.IsSuccess()) +// { +// if (res.IsSuccess()) // .. process response // } // }; -// +// // HttpSessionManager sessiionManager; // = getStaticInstance(); // auto session = sessionManager.createHttpSession("localhost", 8000); // auto request = session->CreateRequest(); @@ -26,7 +26,6 @@ // // - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -35,94 +34,96 @@ namespace common namespace http { -enum class HttpMethod { - HTTP_GET, - HTTP_POST, - HTTP_PUT, - HTTP_OPTIONS, - HTTP_HEAD, - HTTP_PATCH, - HTTP_DELETE +enum class HttpMethod +{ + HTTP_GET, + HTTP_POST, + HTTP_PUT, + HTTP_OPTIONS, + HTTP_HEAD, + HTTP_PATCH, + HTTP_DELETE }; -enum class HttpSessionState { - CREATED, //session object is created - ONGOING, // http(s) request is ongoing - FINISHED // https(s) reuest is finished +enum class HttpSessionState +{ + CREATED, // session object is created + ONGOING, // http(s) request is ongoing + FINISHED // https(s) reuest is finished }; -using HttpHeader = std::pair; -using HttpBody = std::vector; +using HttpHeader = std::pair; +using HttpBody = std::vector; using HttpStatusCode = uint16_t; class HttpRequest { - public: - - virtual void setMethod(HttpMethod method) noexcept = 0; - - virtual void setURI(const std::string& uri) noexcept = 0; +public: + virtual void setMethod(HttpMethod method) noexcept = 0; - virtual void SetBody( HttpBody& body ) noexcept = 0; + virtual void setURI(const std::string &uri) noexcept = 0; - virtual void AddHeader(const HttpHeader& header) noexcept = 0; + virtual void SetBody(HttpBody &body) noexcept = 0; - virtual void ReplaceHeader(const HttpHeader& header) noexcept = 0; + virtual void AddHeader(const HttpHeader &header) noexcept = 0; - virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; + virtual void ReplaceHeader(const HttpHeader &header) noexcept = 0; + virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; }; -class HttpResponse +class HttpResponse { - public: - virtual const HttpBody& GetBody() const noexcept = 0; +public: + virtual const HttpBody &GetBody() const noexcept = 0; - virtual bool GetNextHeader(nostd::function_ref callable ) const noexcept = 0; + virtual bool GetNextHeader(nostd::function_ref callable) const noexcept = 0; - virtual bool GetNextHeader( const std::string& key, nostd::function_ref callable ) const noexcept = 0; + virtual bool GetNextHeader(const std::string &key, + nostd::function_ref callable) const noexcept = 0; - virtual HttpStatusCode GetStatusCode() const noexcept = 0; + virtual HttpStatusCode GetStatusCode() const noexcept = 0; - virtual bool IsSuccess() const noexcept = 0; - - virtual const std::string& GetErrorMessage() const noexcept = 0; + virtual bool IsSuccess() const noexcept = 0; + virtual const std::string &GetErrorMessage() const noexcept = 0; }; -class HttpResponseHandler { +class HttpResponseHandler +{ - public: - virtual void OnHttpResponse(HttpResponse&) noexcept = 0; +public: + virtual void OnHttpResponse(HttpResponse &) noexcept = 0; }; -class HttpSession { - - public: - virtual std::shared_ptr CreateRequest() noexcept = 0; +class HttpSession +{ - virtual void SendRequest(HttpResponseHandler&) noexcept = 0; +public: + virtual std::shared_ptr CreateRequest() noexcept = 0; - virtual HttpSessionState GetSessionState() const noexcept = 0; + virtual void SendRequest(HttpResponseHandler &) noexcept = 0; - virtual bool CancelSession() noexcept = 0; + virtual HttpSessionState GetSessionState() const noexcept = 0; - virtual bool FinishSession() noexcept = 0; + virtual bool CancelSession() noexcept = 0; + virtual bool FinishSession() noexcept = 0; }; -class HttpSessionManager { - - public: - virtual std::shared_ptr createHttpSession(std::string host, uint16_t port = 80) noexcept = 0 ; +class HttpSessionManager +{ - virtual bool CancelAllSessions() noexcept = 0; +public: + virtual std::shared_ptr createHttpSession(std::string host, + uint16_t port = 80) noexcept = 0; - virtual bool FinishAllSessions() noexcept = 0; + virtual bool CancelAllSessions() noexcept = 0; + virtual bool FinishAllSessions() noexcept = 0; }; -} //http -} //common -} //sdk +} // namespace http +} // namespace common +} // namespace sdk OPENTELEMETRY_END_NAMESPACE From 89c9659e500ee60b803e9603d84e814d76294225 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 18:44:46 +0530 Subject: [PATCH 03/20] spell correct --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index fea0fb9ac6..52edd7e34d 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -49,7 +49,7 @@ enum class HttpSessionState { CREATED, // session object is created ONGOING, // http(s) request is ongoing - FINISHED // https(s) reuest is finished + FINISHED // https(s) request is finished }; using HttpHeader = std::pair; From 2d3991adcc98a837bd7fda45c50bd4520eea6877 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 18:54:14 +0530 Subject: [PATCH 04/20] fix comments --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 52edd7e34d..81658fd773 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -16,7 +16,7 @@ // } // }; // -// HttpSessionManager sessiionManager; // = getStaticInstance(); +// HttpSessionManager sessiionManager; // sdk can provide singleton implementation for it // auto session = sessionManager.createHttpSession("localhost", 8000); // auto request = session->CreateRequest(); // request->AddHeader(..); From a1b0586ff9baff6e9be1047dc3b54f253f38474f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 18:55:42 +0530 Subject: [PATCH 05/20] nit --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 81658fd773..161beca684 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -16,7 +16,7 @@ // } // }; // -// HttpSessionManager sessiionManager; // sdk can provide singleton implementation for it +// HttpSessionManager sessiionManager; // implementer can provide singleton implementation for it // auto session = sessionManager.createHttpSession("localhost", 8000); // auto request = session->CreateRequest(); // request->AddHeader(..); From b8a62222f2466538d18436e38b2865986dc36929 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 18:57:32 +0530 Subject: [PATCH 06/20] nit spell --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 161beca684..d89cc8bfbb 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -16,7 +16,7 @@ // } // }; // -// HttpSessionManager sessiionManager; // implementer can provide singleton implementation for it +// HttpSessionManager sessionManager; // implementer can provide singleton implementation for it // auto session = sessionManager.createHttpSession("localhost", 8000); // auto request = session->CreateRequest(); // request->AddHeader(..); From d3826443a7261d735bd861fc52d992353403f94d Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 20 Oct 2020 19:00:21 +0530 Subject: [PATCH 07/20] more robust example --- sdk/include/opentelemetry/sdk/common/http_client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index d89cc8bfbb..c3d96a1549 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -23,8 +23,8 @@ // ResponseHandler res_handler; // session->SendRequest(res_handler); // session->FinishSession() // optionally in the end. -// -// +// ...shutdown +// sessionManager.FinishAllSessions() OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk From e3baf15679a5236eb924f9ebdc0e03660b09a21f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 21 Oct 2020 11:26:45 +0530 Subject: [PATCH 08/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Reiley Yang --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index c3d96a1549..1af2b21576 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -24,7 +24,7 @@ // session->SendRequest(res_handler); // session->FinishSession() // optionally in the end. // ...shutdown -// sessionManager.FinishAllSessions() +// sessionManager.FinishAllSessions() OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk From c20ba7913bb2a8b837129637951d65c3d6934c6f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 21 Oct 2020 17:54:29 +0530 Subject: [PATCH 09/20] fix review comments --- .../opentelemetry/sdk/common/http_client.h | 126 +++++++++--------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 1af2b21576..4a81646b90 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -6,25 +6,32 @@ #include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/version.h" -// Usage Example -// -// struct ReponseHandler: public HttpResponseHandler { -// void OnHttpResponse(HttpResponse& res) noexcept override -// { -// if (res.IsSuccess()) -// .. process response -// } -// }; -// -// HttpSessionManager sessionManager; // implementer can provide singleton implementation for it -// auto session = sessionManager.createHttpSession("localhost", 8000); -// auto request = session->CreateRequest(); -// request->AddHeader(..); -// ResponseHandler res_handler; -// session->SendRequest(res_handler); -// session->FinishSession() // optionally in the end. -// ...shutdown -// sessionManager.FinishAllSessions() +/* + Usage Example + + struct SimpleReponseHandler: public ResponseHandler { + void OnHttpResponse(HttpResponse& res) noexcept override + { + if (res.IsSuccess()) { + res.GetNextHeader([](std::string name, std::string value) -> bool { + std::cout << "Header Name:" << name << " Header Value:"<< value ; + return true; + }); + .. process response body + } + } + }; + + SessionManager sessionManager; // implementer can provide singleton implementation for it + auto session = sessionManager.createSession("localhost", 8000); + auto request = session->CreateRequest(); + request->AddHeader(..); + SimpleResponseHandler res_handler; + session->SendRequest(res_handler); + session->FinishSession() // optionally in the end. + ...shutdown + sessionManager.FinishAllSessions() +*/ OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -34,90 +41,85 @@ namespace common namespace http { -enum class HttpMethod +enum class Method { - HTTP_GET, - HTTP_POST, - HTTP_PUT, - HTTP_OPTIONS, - HTTP_HEAD, - HTTP_PATCH, - HTTP_DELETE + Get, + Post, + Put, + Options, + Head, + Patch, + Delete }; -enum class HttpSessionState +enum class SessionState { - CREATED, // session object is created - ONGOING, // http(s) request is ongoing - FINISHED // https(s) request is finished + Created, // session object is created + Ongoing, // http(s) request is ongoing + Finished // https(s) request is finished }; -using HttpHeader = std::pair; -using HttpBody = std::vector; -using HttpStatusCode = uint16_t; +using Body = std::vector; +using StatusCode = uint16_t; -class HttpRequest +class Request { public: - virtual void setMethod(HttpMethod method) noexcept = 0; + virtual void setMethod(Method method) noexcept = 0; - virtual void setURI(const std::string &uri) noexcept = 0; + virtual void setUri(const std::string &uri) noexcept = 0; - virtual void SetBody(HttpBody &body) noexcept = 0; + virtual void SetBody(Body &body) noexcept = 0; - virtual void AddHeader(const HttpHeader &header) noexcept = 0; + virtual void AddHeader(const std::string &name, const std::string &value) noexcept = 0; - virtual void ReplaceHeader(const HttpHeader &header) noexcept = 0; + virtual void ReplaceHeader(const std::string &name, const std::string &value) noexcept = 0; virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; }; -class HttpResponse +class Response { public: - virtual const HttpBody &GetBody() const noexcept = 0; + virtual const Body &GetBody() const noexcept = 0; - virtual bool GetNextHeader(nostd::function_ref callable) const noexcept = 0; + virtual bool GetNextHeader( + nostd::function_ref callable) const noexcept = 0; - virtual bool GetNextHeader(const std::string &key, - nostd::function_ref callable) const noexcept = 0; + virtual bool GetNextHeader( + const std::string &key, + nostd::function_ref callable) const noexcept = 0; - virtual HttpStatusCode GetStatusCode() const noexcept = 0; - - virtual bool IsSuccess() const noexcept = 0; - - virtual const std::string &GetErrorMessage() const noexcept = 0; + virtual StatusCode GetStatusCode() const noexcept = 0; }; -class HttpResponseHandler +class ResponseHandler { - public: - virtual void OnHttpResponse(HttpResponse &) noexcept = 0; + virtual void OnResponse(Response &) noexcept = 0; + + virtual void OnError(std::string &) noexcept = 0; }; -class HttpSession +class Session { - public: - virtual std::shared_ptr CreateRequest() noexcept = 0; + virtual std::shared_ptr CreateRequest() noexcept = 0; - virtual void SendRequest(HttpResponseHandler &) noexcept = 0; + virtual void SendRequest(ResponseHandler &) noexcept = 0; - virtual HttpSessionState GetSessionState() const noexcept = 0; + virtual SessionState GetSessionState() const noexcept = 0; virtual bool CancelSession() noexcept = 0; virtual bool FinishSession() noexcept = 0; }; -class HttpSessionManager +class SessionManager { - public: - virtual std::shared_ptr createHttpSession(std::string host, - uint16_t port = 80) noexcept = 0; + virtual std::shared_ptr createSession(std::string host, uint16_t port = 80) noexcept = 0; virtual bool CancelAllSessions() noexcept = 0; From 35df55ac9647d6d99700bd874a12c41781f948c5 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 21 Oct 2020 18:43:32 +0530 Subject: [PATCH 10/20] fix example --- sdk/include/opentelemetry/sdk/common/http_client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 4a81646b90..954f0cb980 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -10,7 +10,7 @@ Usage Example struct SimpleReponseHandler: public ResponseHandler { - void OnHttpResponse(HttpResponse& res) noexcept override + void OnResponse(Response& res) noexcept override { if (res.IsSuccess()) { res.GetNextHeader([](std::string name, std::string value) -> bool { @@ -28,7 +28,7 @@ request->AddHeader(..); SimpleResponseHandler res_handler; session->SendRequest(res_handler); - session->FinishSession() // optionally in the end. + session->FinishSession() // optionally in the end ...shutdown sessionManager.FinishAllSessions() */ From 4c427db5992c7fac1078b8588d93b456de810f2d Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 21 Oct 2020 23:31:49 +0530 Subject: [PATCH 11/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Johannes Tax --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 954f0cb980..65024f29e9 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -66,7 +66,7 @@ class Request { public: - virtual void setMethod(Method method) noexcept = 0; + virtual void SetMethod(Method method) noexcept = 0; virtual void setUri(const std::string &uri) noexcept = 0; From 9f16d11f8738ff705e80e7df918b021a4bfd1e45 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 21 Oct 2020 23:32:06 +0530 Subject: [PATCH 12/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Johannes Tax --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 65024f29e9..a2c445ee8c 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -68,7 +68,7 @@ class Request public: virtual void SetMethod(Method method) noexcept = 0; - virtual void setUri(const std::string &uri) noexcept = 0; + virtual void SetUri(const std::string &uri) noexcept = 0; virtual void SetBody(Body &body) noexcept = 0; From cb3ccb5854955d828e20936cc3e55e1ad078e72e Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 21 Oct 2020 23:32:15 +0530 Subject: [PATCH 13/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Johannes Tax --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index a2c445ee8c..383d9cd22b 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -119,7 +119,7 @@ class Session class SessionManager { public: - virtual std::shared_ptr createSession(std::string host, uint16_t port = 80) noexcept = 0; + virtual std::shared_ptr CreateSession(std::string host, uint16_t port = 80) noexcept = 0; virtual bool CancelAllSessions() noexcept = 0; From f8b7af552c6eb88e12654eb9d3e9d990f2e95681 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 22 Oct 2020 00:26:21 +0530 Subject: [PATCH 14/20] review changes --- .../opentelemetry/sdk/common/http_client.h | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 383d9cd22b..b58e2780e0 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -4,6 +4,7 @@ #include #include #include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" /* @@ -13,7 +14,7 @@ void OnResponse(Response& res) noexcept override { if (res.IsSuccess()) { - res.GetNextHeader([](std::string name, std::string value) -> bool { + res.GetNextHeader([](nostd::string_view name, std::string value) -> bool { std::cout << "Header Name:" << name << " Header Value:"<< value ; return true; }); @@ -68,15 +69,17 @@ class Request public: virtual void SetMethod(Method method) noexcept = 0; - virtual void SetUri(const std::string &uri) noexcept = 0; + virtual void SetUri(const nostd::string_view &uri) noexcept = 0; virtual void SetBody(Body &body) noexcept = 0; - virtual void AddHeader(const std::string &name, const std::string &value) noexcept = 0; + virtual void AddHeader(const nostd::string_view &name, const std::string &value) noexcept = 0; - virtual void ReplaceHeader(const std::string &name, const std::string &value) noexcept = 0; + virtual void ReplaceHeader(const nostd::string_view &name, const std::string &value) noexcept = 0; virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; + + virtual ~Request() = default; }; class Response @@ -85,13 +88,17 @@ class Response virtual const Body &GetBody() const noexcept = 0; virtual bool GetNextHeader( - nostd::function_ref callable) const noexcept = 0; + nostd::function_ref callable) const + noexcept = 0; virtual bool GetNextHeader( - const std::string &key, - nostd::function_ref callable) const noexcept = 0; + const nostd::string_view &key, + nostd::function_ref callable) const + noexcept = 0; virtual StatusCode GetStatusCode() const noexcept = 0; + + virtual ~Response() = default; }; class ResponseHandler @@ -99,7 +106,9 @@ class ResponseHandler public: virtual void OnResponse(Response &) noexcept = 0; - virtual void OnError(std::string &) noexcept = 0; + virtual void OnError(nostd::string_view &) noexcept = 0; + + virtual ~ResponseHandler() = default; }; class Session @@ -114,16 +123,21 @@ class Session virtual bool CancelSession() noexcept = 0; virtual bool FinishSession() noexcept = 0; + + virtual ~Session() = default; }; class SessionManager { public: - virtual std::shared_ptr CreateSession(std::string host, uint16_t port = 80) noexcept = 0; + virtual std::shared_ptr CreateSession(nostd::string_view host, + uint16_t port = 80) noexcept = 0; virtual bool CancelAllSessions() noexcept = 0; virtual bool FinishAllSessions() noexcept = 0; + + virtual ~SessionManager() = default; }; } // namespace http } // namespace common From 74558caab65a4af71b8a77f0618715377d221aa9 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 22 Oct 2020 00:32:17 +0530 Subject: [PATCH 15/20] fix sample --- sdk/include/opentelemetry/sdk/common/http_client.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index b58e2780e0..5ba978de21 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -21,6 +21,11 @@ .. process response body } } + + void OnError(nostd::string_view err) noexcept override + { + std::cout << " Error:" << err; + } }; SessionManager sessionManager; // implementer can provide singleton implementation for it @@ -65,7 +70,6 @@ using StatusCode = uint16_t; class Request { - public: virtual void SetMethod(Method method) noexcept = 0; From ae0e5e1ee4568da0b4bd62f8628af8cf55618fc2 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 23 Oct 2020 14:12:56 +0530 Subject: [PATCH 16/20] add intermediate states --- .../opentelemetry/sdk/common/http_client.h | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 5ba978de21..8f9939887d 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -60,13 +60,24 @@ enum class Method enum class SessionState { - Created, // session object is created - Ongoing, // http(s) request is ongoing - Finished // https(s) request is finished + Created, // session object is created + Ongoing, // session is ongoing + Finished, // session is finished ( this needs to be the final state ) + Queued, // http request is queued + TimedOut, // Request timedout, no response received + Aborted, // http request aborted due to local error, + Cancelled, // http request cancelled, possibly due to session->CancelSession(); + SendingFailed, // http request sending failed + NetworkError, // network error + SSLHandshakeFailed, // ssl handshake failed + ReadError, // error while reading response + WriteError // error while writing rquest }; -using Body = std::vector; -using StatusCode = uint16_t; +using Byte = uint8_t; +using StatusCode = uint16_t; +using Body = std::vector; +using SSLCertificate = std::vector; class Request { @@ -91,11 +102,11 @@ class Response public: virtual const Body &GetBody() const noexcept = 0; - virtual bool GetNextHeader( + virtual bool ForEachHeader( nostd::function_ref callable) const noexcept = 0; - virtual bool GetNextHeader( + virtual bool ForEachHeader( const nostd::string_view &key, nostd::function_ref callable) const noexcept = 0; @@ -105,14 +116,16 @@ class Response virtual ~Response() = default; }; -class ResponseHandler +class EventHandler { public: virtual void OnResponse(Response &) noexcept = 0; - virtual void OnError(nostd::string_view &) noexcept = 0; + virtual void OnError(SessionState, nostd::string_view &) noexcept = 0; - virtual ~ResponseHandler() = default; + virtual void OnSslValidation(nostd::function_ref) noexcept {} + + virtual ~EventHandler() = default; }; class Session @@ -120,9 +133,9 @@ class Session public: virtual std::shared_ptr CreateRequest() noexcept = 0; - virtual void SendRequest(ResponseHandler &) noexcept = 0; + virtual void SendRequest(EventHandler &) noexcept = 0; - virtual SessionState GetSessionState() const noexcept = 0; + virtual bool IsSessionActive() noexcept = 0; virtual bool CancelSession() noexcept = 0; @@ -143,6 +156,7 @@ class SessionManager virtual ~SessionManager() = default; }; + } // namespace http } // namespace common } // namespace sdk From 6c13a33c995b7ee55d44483514f45409daf35b80 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 23 Oct 2020 21:05:17 +0530 Subject: [PATCH 17/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Johannes Tax --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 8f9939887d..ace0538cf5 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -121,7 +121,7 @@ class EventHandler public: virtual void OnResponse(Response &) noexcept = 0; - virtual void OnError(SessionState, nostd::string_view &) noexcept = 0; + virtual void OnError(SessionState, nostd::string_view) noexcept = 0; virtual void OnSslValidation(nostd::function_ref) noexcept {} From 11c00123c49e5a34b5a9dc1913c383837a4cf9b9 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 23 Oct 2020 21:06:13 +0530 Subject: [PATCH 18/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Johannes Tax --- sdk/include/opentelemetry/sdk/common/http_client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index ace0538cf5..06108cc04f 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -88,9 +88,9 @@ class Request virtual void SetBody(Body &body) noexcept = 0; - virtual void AddHeader(const nostd::string_view &name, const std::string &value) noexcept = 0; + virtual void AddHeader(nostd::string_view name, nostd::string_view value) noexcept = 0; - virtual void ReplaceHeader(const nostd::string_view &name, const std::string &value) noexcept = 0; + virtual void ReplaceHeader(nostd::string_view name, nostd::string_view value) noexcept = 0; virtual void SetTimeoutMs(std::chrono::milliseconds timeout_ms) noexcept = 0; From c03fef1c8aedc8d7bffab462d91eda2a9e1f552b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 23 Oct 2020 21:06:28 +0530 Subject: [PATCH 19/20] Update sdk/include/opentelemetry/sdk/common/http_client.h Co-authored-by: Johannes Tax --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 06108cc04f..340b946ec8 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -84,7 +84,7 @@ class Request public: virtual void SetMethod(Method method) noexcept = 0; - virtual void SetUri(const nostd::string_view &uri) noexcept = 0; + virtual void SetUri(nostd::string_view uri) noexcept = 0; virtual void SetBody(Body &body) noexcept = 0; From 71e66253435a8aac93d1abdf84473b44e9458224 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 23 Oct 2020 22:58:28 +0530 Subject: [PATCH 20/20] fix ssl pinning method --- sdk/include/opentelemetry/sdk/common/http_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/common/http_client.h b/sdk/include/opentelemetry/sdk/common/http_client.h index 340b946ec8..73e54f0fe2 100644 --- a/sdk/include/opentelemetry/sdk/common/http_client.h +++ b/sdk/include/opentelemetry/sdk/common/http_client.h @@ -123,7 +123,7 @@ class EventHandler virtual void OnError(SessionState, nostd::string_view) noexcept = 0; - virtual void OnSslValidation(nostd::function_ref) noexcept {} + virtual void OnConnecting(const SSLCertificate &) noexcept {} virtual ~EventHandler() = default; };