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

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

Issue 681303003: Add HTTPMultipartBuilder and its test. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: 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
OLDNEW
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CRASHPAD_UTIL_NET_HTTP_MULTIPART_BUILDER_H_
16 #define CRASHPAD_UTIL_NET_HTTP_MULTIPART_BUILDER_H_
17
18 #include "base/basictypes.h"
19 #include "base/files/file_path.h"
20 #include "base/memory/scoped_ptr.h"
21
22 #include <map>
Mark Mentovai 2014/10/28 22:34:28 C++ system headers should precede project-local he
Robert Sesek 2014/10/29 19:52:01 Done.
23 #include <string>
24
25 namespace crashpad {
26
27 class HTTPBodyStream;
28
29 //! \brief This class is used to build a MIME multipart message, conforming to
30 //! RFC 2046, for use as a HTTP request body.
31 class HTTPMultipartBuilder {
32 public:
33 HTTPMultipartBuilder();
34 ~HTTPMultipartBuilder();
35
36 //! \brief Sets a `Content-Disposition: form-data` key-value pair.
37 //!
38 //! \param[in] key The key of the form data, specified as the `name` in the
39 //! multipart message.
40 //! \param[in] value The value to set at the \a key. This will overwrite any
41 //! previously set value with the specified key.
42 void SetFormData(const std::string& key, const std::string& value);
Mark Mentovai 2014/10/28 22:34:28 |key| in this method and [the key, see below] in S
Robert Sesek 2014/10/29 19:52:01 Right, I was playing both sides of this coin by en
43
44 //! \brief Specifies the file at \a path to have its contents uploaded as
45 //! multipart data, available at `name` of \a upload_file_name.
Mark Mentovai 2014/10/28 22:34:28 I think this should be a 3-argument call: (const s
Robert Sesek 2014/10/29 19:52:01 Done.
46 //!
47 //! \param[in] upload_file_name The name to give this multipart data. If a
48 //! \a path has already been supplied at this name, a subsequent call
49 //! will overwrite the path with the newly specified one. This is used
50 //! as the `name` in the multipart message.
51 //! \param[in] path The path of the files whose contents will be uploaded.
52 void SetFileAttachment(const std::string& upload_file_name,
53 const base::FilePath& path);
54
55 //! \brief Generates the HTTPBodyStream for the data currently supplied to
56 //! the builder.
57 //!
58 //! \return A caller-owned HTTPBodyStream object.
59 scoped_ptr<HTTPBodyStream> GetBodyStream();
60
61 private:
62 // Generates a random string suitable for use as a multipart boundary.
63 static std::string GenerateBoundaryString();
Mark Mentovai 2014/10/28 22:34:28 Is there even a reason to expose these private sta
Robert Sesek 2014/10/29 19:52:01 No, moved to anon.
64
65 // Escapes the specified name to be suitable for the name field of a
66 // form-data part.
67 static std::string EncodeFieldName(const std::string& name);
68
69 // Returns a string, formatted with a multipart boundary and a field name,
70 // after which the contents of the part at |name| can be appended.
71 static std::string GetFormDataBoundary(const std::string& boundary,
72 const std::string& name);
73
74 std::map<std::string, std::string> form_data_;
75 std::map<std::string, base::FilePath> file_attachments_;
76
77 DISALLOW_COPY_AND_ASSIGN(HTTPMultipartBuilder);
78 };
79
80 } // namespace crashpad
81
82 #endif // CRASHPAD_UTIL_NET_HTTP_MULTIPART_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698