OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_UTIL_NET_HTTP_TRANSPORT_H_ |
| 16 #define CRASHPAD_UTIL_NET_HTTP_TRANSPORT_H_ |
| 17 |
| 18 #include <string> |
| 19 |
| 20 #include "base/basictypes.h" |
| 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "util/net/http_headers.h" |
| 23 |
| 24 namespace crashpad { |
| 25 |
| 26 class HTTPBodyStream; |
| 27 |
| 28 //! \brief HTTPTransport executes a HTTP request using the specified URL, HTTP |
| 29 //! method, headers, and body. This class can only issue a synchronous |
| 30 //! HTTP request. |
| 31 //! |
| 32 //! This class cannot be instantiated directly. A concrete subclass must be |
| 33 //! instantiated instead, which provides an implementation to execute the |
| 34 //! request that is appropriate for the host operating system. |
| 35 class HTTPTransport { |
| 36 public: |
| 37 virtual ~HTTPTransport(); |
| 38 |
| 39 //! \brief Instantiates a concrete HTTPTransport class for the current |
| 40 //! operating system. |
| 41 //! |
| 42 //! \return A new caller-owned HTTPTransport object. |
| 43 static scoped_ptr<HTTPTransport> Create(); |
| 44 |
| 45 //! \brief Sets URL to which the request will be made. |
| 46 //! |
| 47 //! \param[in] url The request URL. |
| 48 void SetURL(const std::string& url); |
| 49 |
| 50 //! \brief Sets the HTTP method to execute. E.g., GET, POST, etc. The default |
| 51 //! method is `"POST"`. |
| 52 //! |
| 53 //! \param[in] http_method The HTTP method. |
| 54 void SetMethod(const std::string& http_method); |
| 55 |
| 56 //! \brief Sets a HTTP header-value pair. |
| 57 //! |
| 58 //! \param[in] header The HTTP header name. Any previous value set at this |
| 59 //! name will be overwritten. |
| 60 //! \param[in] value The value to set for the header. |
| 61 void SetHeader(const std::string& header, const std::string& value); |
| 62 |
| 63 //! \brief Sets the stream object from which to generate the HTTP body. |
| 64 //! |
| 65 //! \param[in] stream A HTTPBodyStream, of which this class will take |
| 66 //! ownership. |
| 67 void SetBodyStream(scoped_ptr<HTTPBodyStream> stream); |
| 68 |
| 69 //! \brief Sets the timeout for the HTTP request. The default is 15 seconds. |
| 70 //! |
| 71 //! \param[in] timeout The request timeout, in seconds. |
| 72 void SetTimeout(double timeout); |
| 73 |
| 74 //! \brief Performs the HTTP request with the configured parameters and waits |
| 75 //! for the execution to complete. |
| 76 //! |
| 77 //! \return Whether or not the request was successful, defined as returning |
| 78 //! a HTTP status 200 (OK) code. |
| 79 virtual bool ExecuteSynchronously() = 0; |
| 80 |
| 81 protected: |
| 82 HTTPTransport(); |
| 83 |
| 84 const std::string& url() const { return url_; } |
| 85 const std::string& method() const { return method_; } |
| 86 const HTTPHeaders& headers() const { return headers_; } |
| 87 HTTPBodyStream* body_stream() const { return body_stream_.get(); } |
| 88 double timeout() const { return timeout_; } |
| 89 |
| 90 private: |
| 91 std::string url_; |
| 92 std::string method_; |
| 93 HTTPHeaders headers_; |
| 94 scoped_ptr<HTTPBodyStream> body_stream_; |
| 95 double timeout_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(HTTPTransport); |
| 98 }; |
| 99 |
| 100 } // namespace crashpad |
| 101 |
| 102 #endif // CRASHPAD_UTIL_NET_HTTP_TRANSPORT_H_ |
OLD | NEW |