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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 class HTTPBodyStream; | 28 class HTTPBodyStream; |
29 | 29 |
30 //! \brief This class is used to build a MIME multipart message, conforming to | 30 //! \brief This class is used to build a MIME multipart message, conforming to |
31 //! RFC 2046, for use as a HTTP request body. | 31 //! RFC 2046, for use as a HTTP request body. |
32 class HTTPMultipartBuilder { | 32 class HTTPMultipartBuilder { |
33 public: | 33 public: |
34 HTTPMultipartBuilder(); | 34 HTTPMultipartBuilder(); |
35 ~HTTPMultipartBuilder(); | 35 ~HTTPMultipartBuilder(); |
36 | 36 |
37 //! \brief Enables or disables `gzip` compression. | |
38 //! | |
39 //! \param[in] gzip_enabled Whether to enable or disable `gzip` compression. | |
40 //! | |
41 //! When `gzip` compression is enabled, the body stream returned by | |
42 //! GetBodyStream() will be `gzip`-compressed, and the content headers set by | |
43 //! PopulateContentHeaders() will contain `Content-Encoding: gzip`. | |
44 void SetGzipEnabled(bool gzip_enabled); | |
45 | |
46 //! \brief Sets a `Content-Disposition: form-data` key-value pair. | 37 //! \brief Sets a `Content-Disposition: form-data` key-value pair. |
47 //! | 38 //! |
48 //! \param[in] key The key of the form data, specified as the `name` in the | 39 //! \param[in] key The key of the form data, specified as the `name` in the |
49 //! multipart message. Any data previously set on this class with this | 40 //! multipart message. Any data previously set on this class with this |
50 //! key will be overwritten. | 41 //! key will be overwritten. |
51 //! \param[in] value The value to set at the \a key. | 42 //! \param[in] value The value to set at the \a key. |
52 void SetFormData(const std::string& key, const std::string& value); | 43 void SetFormData(const std::string& key, const std::string& value); |
53 | 44 |
54 //! \brief Specifies the file at \a path to have its contents uploaded as | 45 //! \brief Specifies the file at \a path to have its contents uploaded as |
55 //! multipart data, available at `name` of \a upload_file_name. | 46 //! multipart data, available at `name` of \a upload_file_name. |
(...skipping 10 matching lines...) Expand all Loading... |
66 const std::string& upload_file_name, | 57 const std::string& upload_file_name, |
67 const base::FilePath& path, | 58 const base::FilePath& path, |
68 const std::string& content_type); | 59 const std::string& content_type); |
69 | 60 |
70 //! \brief Generates the HTTPBodyStream for the data currently supplied to | 61 //! \brief Generates the HTTPBodyStream for the data currently supplied to |
71 //! the builder. | 62 //! the builder. |
72 //! | 63 //! |
73 //! \return A caller-owned HTTPBodyStream object. | 64 //! \return A caller-owned HTTPBodyStream object. |
74 std::unique_ptr<HTTPBodyStream> GetBodyStream(); | 65 std::unique_ptr<HTTPBodyStream> GetBodyStream(); |
75 | 66 |
76 //! \brief Adds the appropriate content headers to \a http_headers. | 67 //! \brief Gets the header pair for `"Content-Type"`. |
77 //! | 68 HTTPHeaders::value_type GetContentType() const; |
78 //! Any headers that this method adds will replace existing headers by the | |
79 //! same name in \a http_headers. | |
80 void PopulateContentHeaders(HTTPHeaders* http_headers) const; | |
81 | 69 |
82 private: | 70 private: |
83 struct FileAttachment { | 71 struct FileAttachment { |
84 std::string filename; | 72 std::string filename; |
85 std::string content_type; | 73 std::string content_type; |
86 base::FilePath path; | 74 base::FilePath path; |
87 }; | 75 }; |
88 | 76 |
89 // Removes elements from both data maps at the specified |key|, to ensure | 77 // Removes elements from both data maps at the specified |key|, to ensure |
90 // uniqueness across the entire HTTP body. | 78 // uniqueness across the entire HTTP body. |
91 void EraseKey(const std::string& key); | 79 void EraseKey(const std::string& key); |
92 | 80 |
93 std::string boundary_; | 81 std::string boundary_; |
94 std::map<std::string, std::string> form_data_; | 82 std::map<std::string, std::string> form_data_; |
95 std::map<std::string, FileAttachment> file_attachments_; | 83 std::map<std::string, FileAttachment> file_attachments_; |
96 bool gzip_enabled_; | |
97 | 84 |
98 DISALLOW_COPY_AND_ASSIGN(HTTPMultipartBuilder); | 85 DISALLOW_COPY_AND_ASSIGN(HTTPMultipartBuilder); |
99 }; | 86 }; |
100 | 87 |
101 } // namespace crashpad | 88 } // namespace crashpad |
102 | 89 |
103 #endif // CRASHPAD_UTIL_NET_HTTP_MULTIPART_BUILDER_H_ | 90 #endif // CRASHPAD_UTIL_NET_HTTP_MULTIPART_BUILDER_H_ |
OLD | NEW |