| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); | 137 curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); |
| 138 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); | 138 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); |
| 139 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ReceiveData); | 139 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ReceiveData); |
| 140 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseText); | 140 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseText); |
| 141 // Request compressed data. Using any supported aglorithm | 141 // Request compressed data. Using any supported aglorithm |
| 142 curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); | 142 curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); |
| 143 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, ReceiveHeader); | 143 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, ReceiveHeader); |
| 144 curl_easy_setopt(curl, CURLOPT_HEADERDATA, &headerData); | 144 curl_easy_setopt(curl, CURLOPT_HEADERDATA, &headerData); |
| 145 | 145 |
| 146 struct curl_slist* headerList = 0; | 146 struct curl_slist* headerList = 0; |
| 147 for (HeaderList::const_iterator it = requestHeaders.begin(); | 147 for (const auto& header : requestHeaders) |
| 148 it != requestHeaders.end(); ++it) | |
| 149 { | 148 { |
| 150 headerList = curl_slist_append(headerList, (it->first + ": " + it->second)
.c_str()); | 149 headerList = curl_slist_append(headerList, (header.first + ": " + header.s
econd).c_str()); |
| 151 } | 150 } |
| 152 if (headerList) | 151 if (headerList) |
| 153 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList); | 152 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList); |
| 154 | 153 |
| 155 result.status = ConvertErrorCode(curl_easy_perform(curl)); | 154 result.status = ConvertErrorCode(curl_easy_perform(curl)); |
| 156 result.responseStatus = headerData.status; | 155 result.responseStatus = headerData.status; |
| 157 result.responseText = responseText.str(); | 156 result.responseText = responseText.str(); |
| 158 for (std::vector<std::string>::iterator it = headerData.headers.begin(); | 157 for (const auto& header : headerData.headers) |
| 159 it != headerData.headers.end(); ++it) | |
| 160 { | 158 { |
| 161 // Parse header name and value out of something like "Foo: bar" | 159 // Parse header name and value out of something like "Foo: bar" |
| 162 std::string header = *it; | |
| 163 size_t colonPos = header.find(':'); | 160 size_t colonPos = header.find(':'); |
| 164 if (colonPos != std::string::npos) | 161 if (colonPos != std::string::npos) |
| 165 { | 162 { |
| 166 size_t nameStart = 0; | 163 size_t nameStart = 0; |
| 167 size_t nameEnd = colonPos; | 164 size_t nameEnd = colonPos; |
| 168 while (nameEnd > nameStart && isspace(header[nameEnd - 1])) | 165 while (nameEnd > nameStart && isspace(header[nameEnd - 1])) |
| 169 nameEnd--; | 166 nameEnd--; |
| 170 | 167 |
| 171 size_t valueStart = colonPos + 1; | 168 size_t valueStart = colonPos + 1; |
| 172 while (valueStart < header.length() && isspace(header[valueStart])) | 169 while (valueStart < header.length() && isspace(header[valueStart])) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 183 } | 180 } |
| 184 } | 181 } |
| 185 } | 182 } |
| 186 | 183 |
| 187 if (headerList) | 184 if (headerList) |
| 188 curl_slist_free_all(headerList); | 185 curl_slist_free_all(headerList); |
| 189 curl_easy_cleanup(curl); | 186 curl_easy_cleanup(curl); |
| 190 } | 187 } |
| 191 return result; | 188 return result; |
| 192 } | 189 } |
| OLD | NEW |