libadblockplus
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
IWebRequest.h
1 /*
2  * This file is part of Adblock Plus <https://adblockplus.org/>,
3  * Copyright (C) 2006-present eyeo GmbH
4  *
5  * Adblock Plus is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 3 as
7  * published by the Free Software Foundation.
8  *
9  * Adblock Plus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ADBLOCK_PLUS_IWEB_REQUEST_H
19 #define ADBLOCK_PLUS_IWEB_REQUEST_H
20 
21 #include <cstdint>
22 #include <functional>
23 #include <memory>
24 #include <vector>
25 #include <string>
26 
27 namespace AdblockPlus
28 {
32  typedef std::vector<std::pair<std::string, std::string>> HeaderList;
33 
38  {
40 
46 #ifdef _WIN32
47  __int64 status;
48 #else
49  int64_t status;
50 #endif
51 
52 
56  HeaderList responseHeaders;
57 
62 
66  std::string responseText;
67  };
68 
72  struct IWebRequest
73  {
78  {
79  NS_OK = 0,
80  NS_ERROR_FAILURE = 0x80004005,
81  NS_ERROR_OUT_OF_MEMORY = 0x8007000e,
82  NS_ERROR_MALFORMED_URI = 0x804b000a,
83  NS_ERROR_CONNECTION_REFUSED = 0x804b000d,
84  NS_ERROR_NET_TIMEOUT = 0x804b000e,
85  NS_ERROR_NO_CONTENT = 0x804b0011,
86  NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012,
87  NS_ERROR_NET_RESET = 0x804b0014,
88  NS_ERROR_UNKNOWN_HOST = 0x804b001e,
89  NS_ERROR_REDIRECT_LOOP = 0x804b001f,
90  NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a,
91  NS_ERROR_NET_INTERRUPT = 0x804b0047,
92  NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048,
93  NS_CUSTOM_ERROR_BASE = 0x80850000,
94  NS_ERROR_NOT_INITIALIZED = 0xc1f30001
95  };
96 
101  typedef std::function<void(const ServerResponse&)> GetCallback;
102  virtual ~IWebRequest() {};
103 
110  virtual void GET(const std::string& url, const HeaderList& requestHeaders, const GetCallback& getCallback) = 0;
111  };
112 
116  typedef std::unique_ptr<IWebRequest> WebRequestPtr;
117 
118 
123  {
124  virtual ~IWebRequestSync() {}
125  virtual ServerResponse GET(const std::string& url, const HeaderList& requestHeaders) const = 0;
126  };
127  typedef std::unique_ptr<IWebRequestSync> WebRequestSyncPtr;
128 }
129 
130 #endif
std::unique_ptr< IWebRequest > WebRequestPtr
Unique smart pointer to an instance of IWebRequest implementation.
Definition: IWebRequest.h:116
Private functionality.
Definition: IWebRequest.h:122
int64_t status
Mozilla status code indicating the network-level request status.
Definition: IWebRequest.h:49
int responseStatus
HTTP status of the response (e.g. 404).
Definition: IWebRequest.h:61
HTTP response.
Definition: IWebRequest.h:37
std::vector< std::pair< std::string, std::string > > HeaderList
List of HTTP headers.
Definition: IWebRequest.h:32
Web request interface used to implement XMLHttpRequest.
Definition: IWebRequest.h:72
HeaderList responseHeaders
List of response headers.
Definition: IWebRequest.h:56
Main namespace of libadblockplus.
Definition: ActiveObject.h:23
std::string responseText
Body text of the response.
Definition: IWebRequest.h:66
MozillaStatusCode
Possible Mozilla status codes.
Definition: IWebRequest.h:77
virtual void GET(const std::string &url, const HeaderList &requestHeaders, const GetCallback &getCallback)=0
Performs a GET request.
std::function< void(const ServerResponse &)> GetCallback
Callback type invoked when the server response is ready.
Definition: IWebRequest.h:101