OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_HTTP_HTTP_UTIL_H_ | 5 #ifndef NET_HTTP_HTTP_UTIL_H_ |
6 #define NET_HTTP_HTTP_UTIL_H_ | 6 #define NET_HTTP_HTTP_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/string_tokenizer.h" | 13 #include "base/string_tokenizer.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
16 | 16 |
17 // This is a macro to support extending this string literal at compile time. | 17 // This is a macro to support extending this string literal at compile time. |
18 // Please excuse me polluting your global namespace! | 18 // Please excuse me polluting your global namespace! |
19 #define HTTP_LWS " \t" | 19 #define HTTP_LWS " \t" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 class HttpAuthController; | 23 class HttpAuthController; |
24 struct HttpRequestInfo; | 24 struct HttpRequestInfo; |
25 class HttpRequestHeaders; | 25 class HttpRequestHeaders; |
26 class HttpStream; | 26 class HttpStream; |
27 class UploadDataStream; | 27 class UploadDataStream; |
28 | 28 |
29 const char kHttpScheme[] = "http"; | |
30 const char kHttpsScheme[] = "https"; | |
31 const char kDataScheme[] = "data"; | |
32 const int64 kPositionNotSpecified = -1; | |
33 const int kHttpOK = 200; | |
34 const int kHttpPartialContent = 206; | |
35 | |
36 // Define the number of bytes in a megabyte. | |
37 const size_t kMegabyte = 1024 * 1024; | |
38 | |
39 // Backward capacity of the buffer, by default 2MB. | |
40 const size_t kBackwardCapcity = 2 * kMegabyte; | |
41 | |
42 // Forward capacity of the buffer, by default 10MB. | |
43 const size_t kForwardCapacity = 10 * kMegabyte; | |
44 | |
45 // The threshold of bytes that we should wait until the data arrives in the | |
46 // future instead of restarting a new connection. This number is defined in the | |
47 // number of bytes, we should determine this value from typical connection speed | |
48 // and amount of time for a suitable wait. Now I just make a guess for this | |
49 // number to be 2MB. | |
50 // TODO(hclam): determine a better value for this. | |
51 const int kForwardWaitThreshold = 2 * kMegabyte; | |
52 | |
53 // Defines how long we should wait for more data before we declare a connection | |
54 // timeout and start a new request. | |
55 // TODO(hclam): We should really remove this (crbug.com/64571). | |
56 const int kTimeoutMilliseconds = 5000; | |
57 | |
58 // Defines how many times we should try to read from a buffered resource loader | |
59 // before we declare a read error. After each failure of read from a buffered | |
60 // resource loader, a new one is created to be read. | |
61 const int kReadTrials = 3; | |
62 | |
63 // BufferedDataSource has an intermediate buffer, this value governs the initial | |
64 // size of that buffer. It is set to 32KB because this is a typical read size | |
65 // of FFmpeg. | |
66 const int kInitialReadBufferSize = 32768; | |
scherkus (not reviewing)
2010/12/14 18:48:19
I don't think most of these constants belong here
annacc
2010/12/14 21:10:17
OK, I've moved the rest back where they belong, so
annacc
2010/12/14 21:30:44
Scratch the bit about adding ericroman, he's on va
| |
67 | |
29 class HttpUtil { | 68 class HttpUtil { |
30 public: | 69 public: |
31 // Returns the absolute path of the URL, to be used for the http request. | 70 // Returns the absolute path of the URL, to be used for the http request. |
32 // The absolute path starts with a '/' and may contain a query. | 71 // The absolute path starts with a '/' and may contain a query. |
33 static std::string PathForRequest(const GURL& url); | 72 static std::string PathForRequest(const GURL& url); |
34 | 73 |
35 // Returns the absolute URL, to be used for the http request. This url is | 74 // Returns the absolute URL, to be used for the http request. This url is |
36 // made up of the protocol, host, [port], path, [query]. Everything else | 75 // made up of the protocol, host, [port], path, [query]. Everything else |
37 // is stripped (username, password, reference). | 76 // is stripped (username, password, reference). |
38 static std::string SpecForRequest(const GURL& url); | 77 static std::string SpecForRequest(const GURL& url); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 // |enable_proxy_auth| is true. | 209 // |enable_proxy_auth| is true. |
171 static void BuildRequestHeaders(const HttpRequestInfo* request_info, | 210 static void BuildRequestHeaders(const HttpRequestInfo* request_info, |
172 const UploadDataStream* upload_data_stream, | 211 const UploadDataStream* upload_data_stream, |
173 const scoped_refptr<HttpAuthController> | 212 const scoped_refptr<HttpAuthController> |
174 auth_controllers[], | 213 auth_controllers[], |
175 bool enable_server_auth, | 214 bool enable_server_auth, |
176 bool enable_proxy_auth, | 215 bool enable_proxy_auth, |
177 bool enable_full_url, | 216 bool enable_full_url, |
178 HttpRequestHeaders* request_headers); | 217 HttpRequestHeaders* request_headers); |
179 | 218 |
219 // Returns true if |url| operates on HTTP protocol. | |
220 static bool IsHttpProtocol(const GURL& url) { | |
221 return url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme); | |
222 } | |
223 | |
224 static bool IsDataProtocol(const GURL& url) { | |
225 return url.SchemeIs(kDataScheme); | |
226 } | |
227 | |
180 // Used to iterate over the name/value pairs of HTTP headers. To iterate | 228 // Used to iterate over the name/value pairs of HTTP headers. To iterate |
181 // over the values in a multi-value header, use ValuesIterator. | 229 // over the values in a multi-value header, use ValuesIterator. |
182 // See AssembleRawHeaders for joining line continuations (this iterator | 230 // See AssembleRawHeaders for joining line continuations (this iterator |
183 // does not expect any). | 231 // does not expect any). |
184 class HeadersIterator { | 232 class HeadersIterator { |
185 public: | 233 public: |
186 HeadersIterator(std::string::const_iterator headers_begin, | 234 HeadersIterator(std::string::const_iterator headers_begin, |
187 std::string::const_iterator headers_end, | 235 std::string::const_iterator headers_end, |
188 const std::string& line_delimiter); | 236 const std::string& line_delimiter); |
189 ~HeadersIterator(); | 237 ~HeadersIterator(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // into the original's unquoted_value_ member. | 375 // into the original's unquoted_value_ member. |
328 std::string unquoted_value_; | 376 std::string unquoted_value_; |
329 | 377 |
330 bool value_is_quoted_; | 378 bool value_is_quoted_; |
331 }; | 379 }; |
332 }; | 380 }; |
333 | 381 |
334 } // namespace net | 382 } // namespace net |
335 | 383 |
336 #endif // NET_HTTP_HTTP_UTIL_H_ | 384 #endif // NET_HTTP_HTTP_UTIL_H_ |
OLD | NEW |