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