OLD | NEW |
---|---|
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, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 file_attachments_[key] = attachment; | 145 file_attachments_[key] = attachment; |
146 } | 146 } |
147 | 147 |
148 scoped_ptr<HTTPBodyStream> HTTPMultipartBuilder::GetBodyStream() { | 148 scoped_ptr<HTTPBodyStream> HTTPMultipartBuilder::GetBodyStream() { |
149 // The objects inserted into this vector will be owned by the returned | 149 // The objects inserted into this vector will be owned by the returned |
150 // CompositeHTTPBodyStream. Take care to not early-return without deleting | 150 // CompositeHTTPBodyStream. Take care to not early-return without deleting |
151 // this memory. | 151 // this memory. |
152 std::vector<HTTPBodyStream*> streams; | 152 std::vector<HTTPBodyStream*> streams; |
153 | 153 |
154 for (const auto& pair : form_data_) { | 154 for (const auto& pair : form_data_) { |
155 std::string field = GetFormDataBoundary(boundary(), pair.first); | 155 std::string field = GetFormDataBoundary(boundary_, pair.first); |
156 field += kBoundaryCRLF; | 156 field += kBoundaryCRLF; |
157 field += pair.second; | 157 field += pair.second; |
158 field += kCRLF; | 158 field += kCRLF; |
159 streams.push_back(new StringHTTPBodyStream(field)); | 159 streams.push_back(new StringHTTPBodyStream(field)); |
160 } | 160 } |
161 | 161 |
162 for (const auto& pair : file_attachments_) { | 162 for (const auto& pair : file_attachments_) { |
163 const FileAttachment& attachment = pair.second; | 163 const FileAttachment& attachment = pair.second; |
164 std::string header = GetFormDataBoundary(boundary(), pair.first); | 164 std::string header = GetFormDataBoundary(boundary_, pair.first); |
165 header += base::StringPrintf("; filename=\"%s\"%s", | 165 header += base::StringPrintf("; filename=\"%s\"%s", |
166 attachment.filename.c_str(), kCRLF); | 166 attachment.filename.c_str(), kCRLF); |
167 header += base::StringPrintf("Content-Type: %s%s", | 167 header += base::StringPrintf("Content-Type: %s%s", |
168 attachment.content_type.c_str(), kBoundaryCRLF); | 168 attachment.content_type.c_str(), kBoundaryCRLF); |
169 | 169 |
170 streams.push_back(new StringHTTPBodyStream(header)); | 170 streams.push_back(new StringHTTPBodyStream(header)); |
171 streams.push_back(new FileHTTPBodyStream(attachment.path)); | 171 streams.push_back(new FileHTTPBodyStream(attachment.path)); |
172 streams.push_back(new StringHTTPBodyStream(kCRLF)); | 172 streams.push_back(new StringHTTPBodyStream(kCRLF)); |
173 } | 173 } |
174 | 174 |
175 streams.push_back( | 175 streams.push_back( |
176 new StringHTTPBodyStream("--" + boundary() + "--" + kCRLF)); | 176 new StringHTTPBodyStream("--" + boundary_ + "--" + kCRLF)); |
177 | 177 |
178 return scoped_ptr<HTTPBodyStream>(new CompositeHTTPBodyStream(streams)); | 178 return scoped_ptr<HTTPBodyStream>(new CompositeHTTPBodyStream(streams)); |
179 } | 179 } |
180 | 180 |
181 HTTPHeaders::value_type HTTPMultipartBuilder::GetContentType() const { | |
182 std::string content_type = | |
183 base::StringPrintf("multipart/form-data; boundary=%s", boundary_.c_str()); | |
184 return std::make_pair(kContentType, content_type); | |
Mark Mentovai
2014/10/30 21:13:54
#include <utility>
Robert Sesek
2014/10/31 14:48:14
Done.
| |
185 } | |
186 | |
181 void HTTPMultipartBuilder::EraseKey(const std::string& key) { | 187 void HTTPMultipartBuilder::EraseKey(const std::string& key) { |
182 auto data_it = form_data_.find(key); | 188 auto data_it = form_data_.find(key); |
183 if (data_it != form_data_.end()) | 189 if (data_it != form_data_.end()) |
184 form_data_.erase(data_it); | 190 form_data_.erase(data_it); |
185 | 191 |
186 auto file_it = file_attachments_.find(key); | 192 auto file_it = file_attachments_.find(key); |
187 if (file_it != file_attachments_.end()) | 193 if (file_it != file_attachments_.end()) |
188 file_attachments_.erase(file_it); | 194 file_attachments_.erase(file_it); |
189 } | 195 } |
190 | 196 |
191 } // namespace crashpad | 197 } // namespace crashpad |
OLD | NEW |