MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / MultipartEncode

Function MultipartEncode

http.cpp:178–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176
177
178 vector<uint8_t> MultipartEncode(const vector<MultipartField>& fields, string& boundary)
179 {
180 boundary = string(4, '-') + "MultipartFormBoundary" + (string)BNGetUniqueIdentifierString();
181
182 vector<uint8_t> boundaryVec;
183 boundaryVec.reserve(boundary.size());
184 copy(boundary.begin(), boundary.end(), back_inserter(boundaryVec));
185
186 vector<uint8_t> result;
187 size_t expectedSize = boundaryVec.size() * fields.size();
188 for (const auto& field : fields)
189 {
190 expectedSize += field.name.size() + field.content.size();
191 }
192 result.reserve(expectedSize);
193
194 for (const auto& field : fields)
195 {
196 result.push_back('-');
197 result.push_back('-');
198 copy(boundaryVec.begin(), boundaryVec.end(), back_inserter(result));
199 result.push_back('\r');
200 result.push_back('\n');
201 string disposition;
202 if (field.filename)
203 {
204 disposition = string("Content-Disposition: form-data; name=\"") + field.name + "\"; filename=\""
205 + *field.filename + "\"";
206 disposition += string("\r\nContent-Type: application/octet-stream");
207 }
208 else
209 {
210 disposition = string("Content-Disposition: form-data; name=\"") + field.name + "\"";
211 }
212 disposition += "\r\n\r\n";
213
214 copy(disposition.begin(), disposition.end(), back_inserter(result));
215 copy(field.content.begin(), field.content.end(), back_inserter(result));
216
217 result.push_back('\r');
218 result.push_back('\n');
219 }
220 result.push_back('-');
221 result.push_back('-');
222 copy(boundaryVec.begin(), boundaryVec.end(), back_inserter(result));
223 result.push_back('-');
224 result.push_back('-');
225 result.push_back('\r');
226 result.push_back('\n');
227
228 return result;
229 }
230
231
232 Request::Request(string method, string url, const unordered_map<string, string>& headers,

Callers 1

RequestMethod · 0.85

Calls 5

copyFunction · 0.85
push_backMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected