LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #ifndef ADBLOCK_PLUS_WEB_REQUEST_H | 18 #ifndef ADBLOCK_PLUS_WEB_REQUEST_H |
19 #define ADBLOCK_PLUS_WEB_REQUEST_H | 19 #define ADBLOCK_PLUS_WEB_REQUEST_H |
20 | 20 |
21 #include <memory> | 21 #include <memory> |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 #include <string> | 23 #include <string> |
24 #include <vector> | 24 #include <vector> |
25 | 25 |
26 namespace AdblockPlus | 26 namespace AdblockPlus |
27 { | 27 { |
| 28 /** |
| 29 * List of HTTP headers. |
| 30 */ |
28 typedef std::vector<std::pair<std::string, std::string> > HeaderList; | 31 typedef std::vector<std::pair<std::string, std::string> > HeaderList; |
29 | 32 |
| 33 /** |
| 34 * HTTP response. |
| 35 */ |
30 struct ServerResponse | 36 struct ServerResponse |
31 { | 37 { |
| 38 //@{ |
| 39 /** |
| 40 * [Mozilla status code](https://developer.mozilla.org/en/docs/Table_Of_Erro
rs#Network_Errors) |
| 41 * indicating the network-level request status. |
| 42 * This should be 0 (NS_OK) if the request succeeded. Note that this should |
| 43 * be NS_OK if the server responded with an error code like "404 Not Found". |
| 44 */ |
32 #ifdef _WIN32 | 45 #ifdef _WIN32 |
33 __int64 status; | 46 __int64 status; |
34 #else | 47 #else |
35 int64_t status; | 48 int64_t status; |
36 #endif | 49 #endif |
| 50 //@} |
| 51 |
| 52 /** |
| 53 * List of response headers. |
| 54 */ |
37 HeaderList responseHeaders; | 55 HeaderList responseHeaders; |
| 56 |
| 57 /** |
| 58 * HTTP status of the response (e.g.\ 404). |
| 59 */ |
38 int responseStatus; | 60 int responseStatus; |
| 61 |
| 62 /** |
| 63 * Body text of the response. |
| 64 */ |
39 std::string responseText; | 65 std::string responseText; |
40 }; | 66 }; |
41 | 67 |
| 68 /** |
| 69 * Web request interface. |
| 70 */ |
42 class WebRequest | 71 class WebRequest |
43 { | 72 { |
44 public: | 73 public: |
| 74 /** |
| 75 * Possible [Mozilla status codes](https://developer.mozilla.org/en/docs/Tab
le_Of_Errors#Network_Errors). |
| 76 */ |
45 enum | 77 enum |
46 { | 78 { |
47 NS_OK = 0, | 79 NS_OK = 0, |
48 NS_ERROR_FAILURE = 0x80004005, | 80 NS_ERROR_FAILURE = 0x80004005, |
49 NS_ERROR_OUT_OF_MEMORY = 0x8007000e, | 81 NS_ERROR_OUT_OF_MEMORY = 0x8007000e, |
50 NS_ERROR_MALFORMED_URI = 0x804b000a, | 82 NS_ERROR_MALFORMED_URI = 0x804b000a, |
51 NS_ERROR_CONNECTION_REFUSED = 0x804b000d, | 83 NS_ERROR_CONNECTION_REFUSED = 0x804b000d, |
52 NS_ERROR_NET_TIMEOUT = 0x804b000e, | 84 NS_ERROR_NET_TIMEOUT = 0x804b000e, |
53 NS_ERROR_NO_CONTENT = 0x804b0011, | 85 NS_ERROR_NO_CONTENT = 0x804b0011, |
54 NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012, | 86 NS_ERROR_UNKNOWN_PROTOCOL = 0x804b0012, |
55 NS_ERROR_NET_RESET = 0x804b0014, | 87 NS_ERROR_NET_RESET = 0x804b0014, |
56 NS_ERROR_UNKNOWN_HOST = 0x804b001e, | 88 NS_ERROR_UNKNOWN_HOST = 0x804b001e, |
57 NS_ERROR_REDIRECT_LOOP = 0x804b001f, | 89 NS_ERROR_REDIRECT_LOOP = 0x804b001f, |
58 NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a, | 90 NS_ERROR_UNKNOWN_PROXY_HOST = 0x804b002a, |
59 NS_ERROR_NET_INTERRUPT = 0x804b0047, | 91 NS_ERROR_NET_INTERRUPT = 0x804b0047, |
60 NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048, | 92 NS_ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED = 0x804b0048, |
61 NS_CUSTOM_ERROR_BASE = 0x80850000, | 93 NS_CUSTOM_ERROR_BASE = 0x80850000, |
62 NS_ERROR_NOT_INITIALIZED = 0xc1f30001 | 94 NS_ERROR_NOT_INITIALIZED = 0xc1f30001 |
63 }; | 95 }; |
64 | 96 |
65 virtual inline ~WebRequest() {}; | 97 virtual inline ~WebRequest() {}; |
| 98 |
| 99 /** |
| 100 * Performs a GET request. |
| 101 * @param url Request URL. |
| 102 * @param requestHeaders Request headers. |
| 103 * @return HTTP response. |
| 104 */ |
66 virtual ServerResponse GET(const std::string& url, const HeaderList& request
Headers) const = 0; | 105 virtual ServerResponse GET(const std::string& url, const HeaderList& request
Headers) const = 0; |
67 }; | 106 }; |
68 | 107 |
| 108 /** |
| 109 * Shared smart pointer to a `WebRequest` instance. |
| 110 */ |
69 typedef std::shared_ptr<WebRequest> WebRequestPtr; | 111 typedef std::shared_ptr<WebRequest> WebRequestPtr; |
70 } | 112 } |
71 | 113 |
72 #endif | 114 #endif |
LEFT | RIGHT |