Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BUFFET_TRANSPORT_INTERFACE_H_ |
| 6 | #define BUFFET_TRANSPORT_INTERFACE_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | #include <string> |
| 10 | #include <base/basictypes.h> |
| 11 | |
| 12 | namespace chromeos { |
| 13 | namespace http { |
| 14 | |
Alex Vakulenko | b645cc9 | 2014-04-15 11:34:35 -0700 | [diff] [blame] | 15 | typedef std::vector<std::pair<std::string, std::string>> HeaderList; |
| 16 | |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 17 | /////////////////////////////////////////////////////////////////////////////// |
| 18 | // TransportInterface is an interface to abstract specific implementation |
| 19 | // of HTTP communication. This interface (and its underlying implementation) |
| 20 | // is used by http::Request and http::Response classes to provide HTTP |
| 21 | // functionality to the clients. This interface should be of no interest |
| 22 | // to the clients unless they want to implement/use their own network library. |
| 23 | /////////////////////////////////////////////////////////////////////////////// |
| 24 | class TransportInterface { |
| 25 | public: |
| 26 | enum class Stage { |
| 27 | initialized, |
| 28 | response_received, |
| 29 | failed, |
| 30 | closed |
| 31 | }; |
| 32 | |
| 33 | virtual ~TransportInterface() {} |
| 34 | |
| 35 | virtual Stage GetStage() const = 0; |
| 36 | |
| 37 | virtual void AddRange(int64_t bytes) = 0; |
| 38 | virtual void AddRange(uint64_t from_byte, uint64_t to_byte) = 0; |
| 39 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 40 | virtual void SetAccept(const char* accept_mime_types) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 41 | virtual std::string GetAccept() const = 0; |
| 42 | |
| 43 | virtual std::string GetRequestURL() const = 0; |
| 44 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 45 | virtual void SetContentType(const char* content_type) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 46 | virtual std::string GetContentType() const = 0; |
| 47 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 48 | virtual void AddHeader(const char* header, const char* value) = 0; |
| 49 | virtual void RemoveHeader(const char* header) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 50 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 51 | virtual bool AddRequestBody(const void* data, size_t size) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 52 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 53 | virtual void SetMethod(const char* method) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 54 | virtual std::string GetMethod() const = 0; |
| 55 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 56 | virtual void SetReferer(const char* referer) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 57 | virtual std::string GetReferer() const = 0; |
| 58 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 59 | virtual void SetUserAgent(const char* user_agent) = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 60 | virtual std::string GetUserAgent() const = 0; |
| 61 | |
| 62 | virtual bool Perform() = 0; |
| 63 | |
| 64 | virtual int GetResponseStatusCode() const = 0; |
| 65 | virtual std::string GetResponseStatusText() const = 0; |
| 66 | |
Alex Vakulenko | b8ba595 | 2014-04-17 11:35:56 -0700 | [diff] [blame] | 67 | virtual std::string GetResponseHeader(const char* header_name) const = 0; |
| 68 | virtual const std::vector<unsigned char>& GetResponseData() const = 0; |
Chris Sosa | 45d9f10 | 2014-03-24 11:18:54 -0700 | [diff] [blame] | 69 | virtual std::string GetErrorMessage() const = 0; |
| 70 | |
| 71 | virtual void Close() = 0; |
| 72 | |
| 73 | protected: |
| 74 | TransportInterface() {} |
| 75 | DISALLOW_COPY_AND_ASSIGN(TransportInterface); |
| 76 | }; |
| 77 | |
| 78 | } // namespace http |
| 79 | } // namespace chromeos |
| 80 | |
| 81 | #endif // BUFFET_TRANSPORT_INTERFACE_H_ |