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

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

Issue 692963002: Add HTTPTransport, a Mac implementation, and an end-to-end test. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: For landing Created 6 years, 1 month 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
« no previous file with comments | « util/net/http_multipart_builder.h ('k') | util/net/http_transport.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
17 #include <vector> 18 #include <vector>
18 19
19 #include "base/logging.h" 20 #include "base/logging.h"
20 #include "base/rand_util.h" 21 #include "base/rand_util.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "util/net/http_body.h" 23 #include "util/net/http_body.h"
23 24
24 namespace crashpad { 25 namespace crashpad {
25 26
26 namespace { 27 namespace {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 file_attachments_[key] = attachment; 146 file_attachments_[key] = attachment;
146 } 147 }
147 148
148 scoped_ptr<HTTPBodyStream> HTTPMultipartBuilder::GetBodyStream() { 149 scoped_ptr<HTTPBodyStream> HTTPMultipartBuilder::GetBodyStream() {
149 // The objects inserted into this vector will be owned by the returned 150 // The objects inserted into this vector will be owned by the returned
150 // CompositeHTTPBodyStream. Take care to not early-return without deleting 151 // CompositeHTTPBodyStream. Take care to not early-return without deleting
151 // this memory. 152 // this memory.
152 std::vector<HTTPBodyStream*> streams; 153 std::vector<HTTPBodyStream*> streams;
153 154
154 for (const auto& pair : form_data_) { 155 for (const auto& pair : form_data_) {
155 std::string field = GetFormDataBoundary(boundary(), pair.first); 156 std::string field = GetFormDataBoundary(boundary_, pair.first);
156 field += kBoundaryCRLF; 157 field += kBoundaryCRLF;
157 field += pair.second; 158 field += pair.second;
158 field += kCRLF; 159 field += kCRLF;
159 streams.push_back(new StringHTTPBodyStream(field)); 160 streams.push_back(new StringHTTPBodyStream(field));
160 } 161 }
161 162
162 for (const auto& pair : file_attachments_) { 163 for (const auto& pair : file_attachments_) {
163 const FileAttachment& attachment = pair.second; 164 const FileAttachment& attachment = pair.second;
164 std::string header = GetFormDataBoundary(boundary(), pair.first); 165 std::string header = GetFormDataBoundary(boundary_, pair.first);
165 header += base::StringPrintf("; filename=\"%s\"%s", 166 header += base::StringPrintf("; filename=\"%s\"%s",
166 attachment.filename.c_str(), kCRLF); 167 attachment.filename.c_str(), kCRLF);
167 header += base::StringPrintf("Content-Type: %s%s", 168 header += base::StringPrintf("Content-Type: %s%s",
168 attachment.content_type.c_str(), kBoundaryCRLF); 169 attachment.content_type.c_str(), kBoundaryCRLF);
169 170
170 streams.push_back(new StringHTTPBodyStream(header)); 171 streams.push_back(new StringHTTPBodyStream(header));
171 streams.push_back(new FileHTTPBodyStream(attachment.path)); 172 streams.push_back(new FileHTTPBodyStream(attachment.path));
172 streams.push_back(new StringHTTPBodyStream(kCRLF)); 173 streams.push_back(new StringHTTPBodyStream(kCRLF));
173 } 174 }
174 175
175 streams.push_back( 176 streams.push_back(
176 new StringHTTPBodyStream("--" + boundary() + "--" + kCRLF)); 177 new StringHTTPBodyStream("--" + boundary_ + "--" + kCRLF));
177 178
178 return scoped_ptr<HTTPBodyStream>(new CompositeHTTPBodyStream(streams)); 179 return scoped_ptr<HTTPBodyStream>(new CompositeHTTPBodyStream(streams));
179 } 180 }
180 181
182 HTTPHeaders::value_type HTTPMultipartBuilder::GetContentType() const {
183 std::string content_type =
184 base::StringPrintf("multipart/form-data; boundary=%s", boundary_.c_str());
185 return std::make_pair(kContentType, content_type);
186 }
187
181 void HTTPMultipartBuilder::EraseKey(const std::string& key) { 188 void HTTPMultipartBuilder::EraseKey(const std::string& key) {
182 auto data_it = form_data_.find(key); 189 auto data_it = form_data_.find(key);
183 if (data_it != form_data_.end()) 190 if (data_it != form_data_.end())
184 form_data_.erase(data_it); 191 form_data_.erase(data_it);
185 192
186 auto file_it = file_attachments_.find(key); 193 auto file_it = file_attachments_.find(key);
187 if (file_it != file_attachments_.end()) 194 if (file_it != file_attachments_.end())
188 file_attachments_.erase(file_it); 195 file_attachments_.erase(file_it);
189 } 196 }
190 197
191 } // namespace crashpad 198 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/net/http_multipart_builder.h ('k') | util/net/http_transport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698