blob: e833239869be1c3c14769277de51dcec17e96201 [file] [log] [blame]
Chris Sosa45d9f102014-03-24 11:18:54 -07001// 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
12namespace chromeos {
13namespace http {
14
Alex Vakulenkob645cc92014-04-15 11:34:35 -070015typedef std::vector<std::pair<std::string, std::string>> HeaderList;
16
Chris Sosa45d9f102014-03-24 11:18:54 -070017///////////////////////////////////////////////////////////////////////////////
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///////////////////////////////////////////////////////////////////////////////
24class 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 Vakulenkob8ba5952014-04-17 11:35:56 -070040 virtual void SetAccept(const char* accept_mime_types) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070041 virtual std::string GetAccept() const = 0;
42
43 virtual std::string GetRequestURL() const = 0;
44
Alex Vakulenkob8ba5952014-04-17 11:35:56 -070045 virtual void SetContentType(const char* content_type) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070046 virtual std::string GetContentType() const = 0;
47
Alex Vakulenkob8ba5952014-04-17 11:35:56 -070048 virtual void AddHeader(const char* header, const char* value) = 0;
49 virtual void RemoveHeader(const char* header) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070050
Alex Vakulenkob8ba5952014-04-17 11:35:56 -070051 virtual bool AddRequestBody(const void* data, size_t size) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070052
Alex Vakulenkob8ba5952014-04-17 11:35:56 -070053 virtual void SetMethod(const char* method) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070054 virtual std::string GetMethod() const = 0;
55
Alex Vakulenkob8ba5952014-04-17 11:35:56 -070056 virtual void SetReferer(const char* referer) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070057 virtual std::string GetReferer() const = 0;
58
Alex Vakulenkob8ba5952014-04-17 11:35:56 -070059 virtual void SetUserAgent(const char* user_agent) = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070060 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 Vakulenkob8ba5952014-04-17 11:35:56 -070067 virtual std::string GetResponseHeader(const char* header_name) const = 0;
68 virtual const std::vector<unsigned char>& GetResponseData() const = 0;
Chris Sosa45d9f102014-03-24 11:18:54 -070069 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_