1 : // Copyright 2014 Google Inc. 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 SYZYGY_KASKO_INTERNET_HELPERS_H_
16 : #define SYZYGY_KASKO_INTERNET_HELPERS_H_
17 :
18 : #include <Windows.h> // NOLINT
19 :
20 : #include <stdint.h>
21 :
22 : #include <map>
23 : #include <string>
24 : #include "base/strings/string16.h"
25 :
26 m : namespace kasko {
27 :
28 : // Parses the value of a Content-Type header.
29 : // @param content_type_str The value of a Content-Type HTTP header (without the
30 : // label or ':').
31 : // @param mime_type Receives the specified mime-type, if any, in lower-case.
32 : // Unmodified otherwise.
33 : // @param charset Receives the specified charset, if any, in lower-case.
34 : // Unmodified otherwise.
35 : // @param boundary Optional. Receives the (quoted) value of the boundary
36 : // parameter, if any. Unmodified otherwise.
37 m : void ParseContentType(const base::string16& content_type_str,
38 m : base::string16* mime_type,
39 m : base::string16* charset,
40 m : bool* had_charset,
41 m : base::string16* boundary);
42 :
43 : // Parses an URL.
44 : // @param url The URL to parse.
45 : // @param scheme Receives the parsed scheme.
46 : // @param host Receives the parsed host.
47 : // @param port Receives the parsed port (or the implicit default port).
48 : // @param path Receives the parsed path.
49 : // @returns true if the URL is successfully parsed.
50 m : bool DecomposeUrl(const base::string16& url,
51 m : base::string16* scheme,
52 m : base::string16* host,
53 m : uint16_t* port,
54 m : base::string16* path);
55 :
56 : // Composes an HTTP or HTTPS URL.
57 : // @param host The URL host component.
58 : // @param port The URL port component.
59 : // @param path The URL path component.
60 : // @returns The composed URL.
61 m : base::string16 ComposeUrl(const base::string16& host,
62 m : uint16_t port,
63 m : const base::string16& path,
64 m : bool secure);
65 :
66 : // @returns A random string to be used as a multipart MIME message boundary.
67 m : base::string16 GenerateMultipartHttpRequestBoundary();
68 :
69 : // Generates an appropriate Content-Type header (starting with "Content-Type:")
70 : // for a multi-part HTTP message.
71 : // @param boundary The MIME boundary to use.
72 : // @returns An HTTP Content-Type header suitable for the multipart message
73 : // generated by GenerateMultipartHttpRequestBody.
74 m : base::string16 GenerateMultipartHttpRequestContentTypeHeader(
75 m : const base::string16 boundary);
76 :
77 : // Generates a multipart HTTP message body.
78 : // @param parameters HTTP request parameters to be encoded in the body.
79 : // @param upload_file File contents to be encoded in the body.
80 : // @param file_part_name The parameter name to be assigned to the file part.
81 : // @param boundary The MIME boundary to use.
82 : // @returns A multipart HTTP message body.
83 m : std::string GenerateMultipartHttpRequestBody(
84 m : const std::map<base::string16, base::string16>& parameters,
85 m : const std::string& upload_file,
86 m : const base::string16& file_part_name,
87 m : const base::string16& boundary);
88 :
89 m : } // namespace kasko
90 :
91 : #endif // SYZYGY_KASKO_INTERNET_HELPERS_H_
|