blob: fa858c65845641d65b881155ea37ff57c812dd0e [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
15///////////////////////////////////////////////////////////////////////////////
16// TransportInterface is an interface to abstract specific implementation
17// of HTTP communication. This interface (and its underlying implementation)
18// is used by http::Request and http::Response classes to provide HTTP
19// functionality to the clients. This interface should be of no interest
20// to the clients unless they want to implement/use their own network library.
21///////////////////////////////////////////////////////////////////////////////
22class TransportInterface {
23 public:
24 enum class Stage {
25 initialized,
26 response_received,
27 failed,
28 closed
29 };
30
31 virtual ~TransportInterface() {}
32
33 virtual Stage GetStage() const = 0;
34
35 virtual void AddRange(int64_t bytes) = 0;
36 virtual void AddRange(uint64_t from_byte, uint64_t to_byte) = 0;
37
38 virtual void SetAccept(char const* accept_mime_types) = 0;
39 virtual std::string GetAccept() const = 0;
40
41 virtual std::string GetRequestURL() const = 0;
42
43 virtual void SetContentType(char const* content_type) = 0;
44 virtual std::string GetContentType() const = 0;
45
46 virtual void AddHeader(char const* header, char const* value) = 0;
47 virtual void RemoveHeader(char const* header) = 0;
48
49 virtual bool AddRequestBody(void const* data, size_t size) = 0;
50
51 virtual void SetMethod(char const* method) = 0;
52 virtual std::string GetMethod() const = 0;
53
54 virtual void SetReferer(char const* referer) = 0;
55 virtual std::string GetReferer() const = 0;
56
57 virtual void SetUserAgent(char const* user_agent) = 0;
58 virtual std::string GetUserAgent() const = 0;
59
60 virtual bool Perform() = 0;
61
62 virtual int GetResponseStatusCode() const = 0;
63 virtual std::string GetResponseStatusText() const = 0;
64
65 virtual std::string GetResponseHeader(char const* header_name) const = 0;
66 virtual std::vector<unsigned char> const& GetResponseData() const = 0;
67 virtual std::string GetErrorMessage() const = 0;
68
69 virtual void Close() = 0;
70
71 protected:
72 TransportInterface() {}
73 DISALLOW_COPY_AND_ASSIGN(TransportInterface);
74};
75
76} // namespace http
77} // namespace chromeos
78
79#endif // BUFFET_TRANSPORT_INTERFACE_H_