Andreea Costinas | 90b7164 | 2020-06-12 10:18:25 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | #ifndef SYSTEM_PROXY_HTTP_UTIL_H_ |
| 5 | #define SYSTEM_PROXY_HTTP_UTIL_H_ |
| 6 | |
| 7 | #include <string> |
| 8 | #include <utility> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/strings/string_util.h> |
| 12 | |
| 13 | // TODO(acostinas,crbug.com/1094205): Add fuzzer tests. |
| 14 | namespace system_proxy { |
| 15 | |
| 16 | // List of scheme and realm pairs. The |first| item in each entry represents the |
| 17 | // HTTP authentication scheme and |second| item represents the realm of the |
| 18 | // server where the challenge is originating from. |
| 19 | using SchemeRealmPairList = std::vector<std::pair<std::string, std::string>>; |
| 20 | |
| 21 | // Verifies if the http headers are ending with an http empty line, meaning a |
| 22 | // line that contains only CRLF or LF preceded by a line ending with CRLF. |
| 23 | bool IsEndingWithHttpEmptyLine(const base::StringPiece& http_header_line); |
| 24 | |
| 25 | // Parses the first line of the http CONNECT request and extracts the URI |
| 26 | // authority, defined in RFC3986, section 3.2, as the host name and port number |
| 27 | // separated by a colon. The destination URI is specified in the request line |
| 28 | // (RFC2817, section 5.2): |
| 29 | // CONNECT server.example.com:80 HTTP/1.1 |
| 30 | // If the first line in |raw_request| (the Request-Line) is a correctly formed |
| 31 | // CONNECT request, it will return the destination URI as host:port, otherwise |
| 32 | // it will return an empty string. |
| 33 | std::string GetUriAuthorityFromHttpHeader( |
| 34 | const base::StringPiece& http_request); |
| 35 | |
| 36 | // Parses the HTTP server reply and extracts the supported authentication scheme |
| 37 | // and realm. |
| 38 | SchemeRealmPairList ParseAuthChallenge(const base::StringPiece& http_request); |
| 39 | |
| 40 | } // namespace system_proxy |
| 41 | |
| 42 | #endif // SYSTEM_PROXY_HTTP_UTIL_H_ |