• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_BASE_APPLE_HTTP_RESPONSE_HEADERS_UTIL_H_
6 #define NET_BASE_APPLE_HTTP_RESPONSE_HEADERS_UTIL_H_
7 
8 #include "net/base/net_export.h"
9 #include "net/http/http_response_headers.h"
10 
11 @class NSHTTPURLResponse;
12 
13 namespace net {
14 
15 // Placeholder status description since the actual text from the headers is not
16 // available.
17 extern const char kDummyHttpStatusDescription[];
18 
19 // Tries to decode `string` as if it was a "utf-8" encoded string incorrectly
20 // decoded as "latin1" encoded string. Returns the original string if it does
21 // not appear to be a mis-decoded string.
22 //
23 // HTTP headers have no encoding, but NSHTTPURLResponse decode them as if they
24 // were using "latin1" encoding as the rfc recommends (see [1]). Servers do
25 // sometime sends data in "utf-8" encoding. Interpreting "utf-8" encoded string
26 // as "latin1" results in garbled characters as soon as the string contains non
27 // US-ASCII characters (aka mojibake). Hopefully, this incorrect decoding is
28 // reversible as "latin1" maps each bytes to the same unicode character (i.e.
29 // byte '\xab' maps to '\u00ab'). See [2] for example of a web server serving
30 // "utf-8" encoded string incorrectly decoded.
31 //
32 // [1]: https://www.rfc-editor.org/rfc/rfc7230#section-3.2.4.
33 // [2]: https://crbug.com/1333351
34 NET_EXPORT NSString* FixNSStringIncorrectlyDecodedAsLatin1(NSString* string);
35 
36 // Constructs a net::HttpResponseHeaders from |response|.
37 // Note: The HTTP version and the status code description are not accessible
38 // from NSHTTPURLResponse, so HTTP/1.0 and kDummyHttpStatusDescription will
39 // be used in the status line instead.
40 NET_EXPORT scoped_refptr<HttpResponseHeaders>
41 CreateHeadersFromNSHTTPURLResponse(NSHTTPURLResponse* response);
42 
43 }  // namespace net
44 
45 #endif  // NET_BASE_APPLE_HTTP_RESPONSE_HEADERS_UTIL_H_
46