Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/DefaultWebRequestCurl.cpp

Issue 29391775: Issue 5013 - Improve some const-correctness (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created March 22, 2017, 3:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/FilterEngine.cpp » ('j') | src/WebRequestJsObject.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
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 (auto it = requestHeaders.cbegin(); it != requestHeaders.cend(); ++it)
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, (it->first + ": " + it->second) .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 (auto it = headerData.headers.cbegin(); it != headerData.headers.cend(); ++it)
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; 160 std::string header = *it;
163 size_t colonPos = header.find(':'); 161 size_t colonPos = header.find(':');
164 if (colonPos != std::string::npos) 162 if (colonPos != std::string::npos)
165 { 163 {
166 size_t nameStart = 0; 164 size_t nameStart = 0;
167 size_t nameEnd = colonPos; 165 size_t nameEnd = colonPos;
168 while (nameEnd > nameStart && isspace(header[nameEnd - 1])) 166 while (nameEnd > nameStart && isspace(header[nameEnd - 1]))
169 nameEnd--; 167 nameEnd--;
(...skipping 13 matching lines...) Expand all
183 } 181 }
184 } 182 }
185 } 183 }
186 184
187 if (headerList) 185 if (headerList)
188 curl_slist_free_all(headerList); 186 curl_slist_free_all(headerList);
189 curl_easy_cleanup(curl); 187 curl_easy_cleanup(curl);
190 } 188 }
191 return result; 189 return result;
192 } 190 }
OLDNEW
« no previous file with comments | « no previous file | src/FilterEngine.cpp » ('j') | src/WebRequestJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld