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

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: Assert safe MIME types 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 <map>
19 #include <string>
20
21 #include "base/basictypes.h"
22 #include "base/files/file_path.h"
23 #include "base/memory/scoped_ptr.h"
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. Any data previously set on this class with this
40 //! key will be overwritten.
41 //! \param[in] value The value to set at the \a key.
42 void SetFormData(const std::string& key, const std::string& value);
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.
46 //!
47 //! \param[in] key The key of the form data, specified as the `name` in the
48 //! multipart message. Any data previously set on this class with this
49 //! key will be overwritten.
50 //! \param[in] upload_file_name The `filename` to specify for this multipart
51 //! data attachment.
52 //! \param[in] path The path of the file whose contents will be uploaded.
53 //! \param[in] content_type The `Content-Type` to specify for the attachment.
54 //! If this is empty, `"application/octet-stream"` will be used.
55 void SetFileAttachment(const std::string& key,
56 const std::string& upload_file_name,
57 const base::FilePath& path,
58 const std::string& content_type);
59
60 //! \brief Generates the HTTPBodyStream for the data currently supplied to
61 //! the builder.
62 //!
63 //! \return A caller-owned HTTPBodyStream object.
64 scoped_ptr<HTTPBodyStream> GetBodyStream();
65
66 //! \brief Gets the boundary that will be used in GetBodyStream().
67 std::string boundary() const { return boundary_; }
68
69 private:
70 struct FileAttachment {
71 std::string filename;
72 std::string content_type;
73 base::FilePath path;
74 };
75
76 // Removes elements from both data maps at the specified |key|, to ensure
77 // uniqueness across the entire HTTP body.
78 void EraseKey(const std::string& key);
79
80 std::string boundary_;
81 std::map<std::string, std::string> form_data_;
82 std::map<std::string, FileAttachment> file_attachments_;
83
84 DISALLOW_COPY_AND_ASSIGN(HTTPMultipartBuilder);
85 };
86
87 } // namespace crashpad
88
89 #endif // CRASHPAD_UTIL_NET_HTTP_MULTIPART_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698