Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: third_party/crashpad/crashpad/util/net/http_multipart_builder.cc

Issue 2710663006: Update Crashpad to 4a2043ea65e2641ef1a921801c0aaa15ada02fc7 (Closed)
Patch Set: Update Crashpad to 4a2043ea65e2 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/net/http_multipart_builder.h" 15 #include "util/net/http_multipart_builder.h"
16 16
17 #include <sys/types.h> 17 #include <sys/types.h>
18 18
19 #include <utility> 19 #include <utility>
20 #include <vector> 20 #include <vector>
21 21
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/rand_util.h" 23 #include "base/rand_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "util/net/http_body.h" 25 #include "util/net/http_body.h"
26 #include "util/net/http_body_gzip.h"
26 27
27 namespace crashpad { 28 namespace crashpad {
28 29
29 namespace { 30 namespace {
30 31
31 const char kCRLF[] = "\r\n"; 32 const char kCRLF[] = "\r\n";
32 33
33 const char kBoundaryCRLF[] = "\r\n\r\n"; 34 const char kBoundaryCRLF[] = "\r\n\r\n";
34 35
35 // Generates a random string suitable for use as a multipart boundary. 36 // Generates a random string suitable for use as a multipart boundary.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 c == '.' || 110 c == '.' ||
110 c == '_' || 111 c == '_' ||
111 c == '+' || 112 c == '+' ||
112 c == '-'); 113 c == '-');
113 } 114 }
114 } 115 }
115 116
116 } // namespace 117 } // namespace
117 118
118 HTTPMultipartBuilder::HTTPMultipartBuilder() 119 HTTPMultipartBuilder::HTTPMultipartBuilder()
119 : boundary_(GenerateBoundaryString()), form_data_(), file_attachments_() { 120 : boundary_(GenerateBoundaryString()),
121 form_data_(),
122 file_attachments_(),
123 gzip_enabled_(false) {}
124
125 HTTPMultipartBuilder::~HTTPMultipartBuilder() {
120 } 126 }
121 127
122 HTTPMultipartBuilder::~HTTPMultipartBuilder() { 128 void HTTPMultipartBuilder::SetGzipEnabled(bool gzip_enabled) {
129 gzip_enabled_ = gzip_enabled;
123 } 130 }
124 131
125 void HTTPMultipartBuilder::SetFormData(const std::string& key, 132 void HTTPMultipartBuilder::SetFormData(const std::string& key,
126 const std::string& value) { 133 const std::string& value) {
127 EraseKey(key); 134 EraseKey(key);
128 form_data_[key] = value; 135 form_data_[key] = value;
129 } 136 }
130 137
131 void HTTPMultipartBuilder::SetFileAttachment( 138 void HTTPMultipartBuilder::SetFileAttachment(
132 const std::string& key, 139 const std::string& key,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 attachment.content_type.c_str(), kBoundaryCRLF); 179 attachment.content_type.c_str(), kBoundaryCRLF);
173 180
174 streams.push_back(new StringHTTPBodyStream(header)); 181 streams.push_back(new StringHTTPBodyStream(header));
175 streams.push_back(new FileHTTPBodyStream(attachment.path)); 182 streams.push_back(new FileHTTPBodyStream(attachment.path));
176 streams.push_back(new StringHTTPBodyStream(kCRLF)); 183 streams.push_back(new StringHTTPBodyStream(kCRLF));
177 } 184 }
178 185
179 streams.push_back( 186 streams.push_back(
180 new StringHTTPBodyStream("--" + boundary_ + "--" + kCRLF)); 187 new StringHTTPBodyStream("--" + boundary_ + "--" + kCRLF));
181 188
182 return std::unique_ptr<HTTPBodyStream>(new CompositeHTTPBodyStream(streams)); 189 auto composite =
190 std::unique_ptr<HTTPBodyStream>(new CompositeHTTPBodyStream(streams));
191 if (gzip_enabled_) {
192 return std::unique_ptr<HTTPBodyStream>(
193 new GzipHTTPBodyStream(std::move(composite)));
194 }
195 return composite;
183 } 196 }
184 197
185 HTTPHeaders::value_type HTTPMultipartBuilder::GetContentType() const { 198 void HTTPMultipartBuilder::PopulateContentHeaders(
199 HTTPHeaders* http_headers) const {
186 std::string content_type = 200 std::string content_type =
187 base::StringPrintf("multipart/form-data; boundary=%s", boundary_.c_str()); 201 base::StringPrintf("multipart/form-data; boundary=%s", boundary_.c_str());
188 return std::make_pair(kContentType, content_type); 202 (*http_headers)[kContentType] = content_type;
203
204 if (gzip_enabled_) {
205 (*http_headers)[kContentEncoding] = "gzip";
206 }
189 } 207 }
190 208
191 void HTTPMultipartBuilder::EraseKey(const std::string& key) { 209 void HTTPMultipartBuilder::EraseKey(const std::string& key) {
192 auto data_it = form_data_.find(key); 210 auto data_it = form_data_.find(key);
193 if (data_it != form_data_.end()) 211 if (data_it != form_data_.end())
194 form_data_.erase(data_it); 212 form_data_.erase(data_it);
195 213
196 auto file_it = file_attachments_.find(key); 214 auto file_it = file_attachments_.find(key);
197 if (file_it != file_attachments_.end()) 215 if (file_it != file_attachments_.end())
198 file_attachments_.erase(file_it); 216 file_attachments_.erase(file_it);
199 } 217 }
200 218
201 } // namespace crashpad 219 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698