// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine License // Agreement. #ifndef CDM_TEST_URL_REQUEST_H_ #define CDM_TEST_URL_REQUEST_H_ #include #include #include "http_socket.h" #include "wv_class_utils.h" namespace wvcdm { // Provides simple HTTP request and response service. // Only POST request method is implemented. class UrlRequest { public: UrlRequest() = delete; WVCDM_DISALLOW_COPY_AND_MOVE(UrlRequest); explicit UrlRequest(const std::string& url); ~UrlRequest(); bool is_connected() const { return is_connected_; } void Reconnect(); bool PostRequest(const std::string& data); bool PostCertRequestInQueryString(const std::string& data); bool GetResponse(std::string* message); static int GetStatusCode(const std::string& response); // Get the response, and expect the status is OK. // It will retry if the response code is in the 500 range. void AssertOkResponseWithRetry(std::string* message); static bool GetDebugHeaderFields( const std::string& response, std::map* header_fields); private: bool PostRequestWithPath(const std::string& path, const std::string& data); bool SendRequestOnce(); bool is_connected_; HttpSocket socket_; std::string request_; }; // class UrlRequest } // namespace wvcdm #endif // CDM_TEST_URL_REQUEST_H_