mz_http_proxy/lib.rs
1// Copyright Materialize, Inc. and contributors. 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 in the LICENSE file at the
6// root of this repository, or online at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#![deny(missing_docs)]
17#![cfg_attr(nightly_doc_features, feature(doc_cfg))]
18
19//! [<img src="https://materialize.com/wp-content/uploads/2020/01/materialize_logo_primary.png" width=180 align=right>](https://materialize.com)
20//!
21//! HTTP proxy adapters.
22//!
23//! This crate constructs HTTP clients that respect the system's proxy
24//! configuration.
25//!
26//! # Maintainership
27//!
28//! This crate is developed as part of [Materialize], the streaming data
29//! warehouse. Contributions are encouraged:
30//!
31//! * [View source code](https://github.com/MaterializeInc/materialize/tree/main/src/http-proxy)
32//! * [Report an issue](https://github.com/MaterializeInc/materialize/issues/new/choose)
33//! * [Submit a pull request](https://github.com/MaterializeInc/materialize/compare)
34//!
35//! # Features
36//!
37//! All features are disabled by default. You will likely want to enable at
38//! least one of the following features depending on the HTTP client library you
39//! use:
40//!
41//! * The **`hyper`** feature enables the proxy adapters for use with the
42//! [`hyper` crate](https://docs.rs/hyper).
43//!
44//! * The **`reqwest`** feature enables the proxy adapters for use with the
45//! [`reqwest` crate](https://docs.rs/reqwest).
46//!
47//! Note that `reqwest` by default will perform its own determination of the
48//! system proxy configuration, but its support for `no_proxy` is not as
49//! complete as the implementation in this crate.
50//!
51//! # System proxy configuration
52//!
53//! The system's proxy configuration is governed by four environment variables,
54//! `http_proxy`, `https_proxy`, `all_proxy`, and `no_proxy`, whose meanings are
55//! nonstandard and vary widely from tool to tool. Materialize implements a
56//! subset of the behavior that has been empirically determined to be common to
57//! many other HTTP clients.
58//!
59//! With the exception of `http_proxy`, environment variables may be specified
60//! in all lowercase, as written above, or in all uppercase (e.g,
61//! `HTTPS_PROXY`). `http_proxy` is accepted in lowercase only because the
62//! variable `HTTP_PROXY` can be controlled by attackers in CGI environments, as
63//! in [golang/go#16405]. If an environment variable is specified in both
64//! lowercase and uppercase, the lowercase variable takes precedence.
65//!
66//! ## Proxy selection
67//!
68//! The `http_proxy` and `https_proxy` environment variables specify the URL of
69//! a proxy server to use when routing HTTP and HTTPS traffic, respectively. The
70//! `all_proxy` environment variable specifies a proxy server that applies to
71//! both HTTP and HTTPS traffic. `http_proxy` and `https_proxy` take precedence
72//! over `all_proxy`.
73//!
74//! ## Proxy exclusions
75//!
76//! The `no_proxy` environment variable is a comma-separated list specifying
77//! hosts to exclude from proxying. It takes precedence over the other
78//! environment variables. Each entry in the list must be:
79//!
80//! * an IP address followed by an optional port (e.g., `1.2.3.4`,
81//! `1.2.3.4:80`, `::1`, `[::1]`, or `[::1]:80`),
82//! * an IP address prefix in CIDR notation (e.g., `1.1.0.0/16`), or
83//! * a domain name followed by an optional port (e.g., `foo.com`).
84//!
85//! Whitespace surrounding an entry is ignored.
86//!
87//! IPv6 addresses cannot contain whitespace inside the `[` and `]` characters
88//! or they will be treated as domains. IPv6 addresses that are followed by a
89//! port specification must be surrounded by `[` and `]` or the port will be
90//! considered part of the IPv6 address. (The implementation technically allows
91//! IPv4 addresses to be wrapped in square brackets as well, for compatibility
92//! with other tools, but this should not be relied upon.)
93//!
94//! `no_proxy` matching never involves DNS resolution, so a `no_proxy` value of
95//! `1.2.3.4` will exclude requests that literally mention the IP in the URL
96//! (e.g., `http://1.2.3.4`) from proxying, but not requests to
97//! `http://domainthatresolvesto1234`.
98//!
99//! Domain names in `no_proxy` match all subdomains, so a `no_proxy` value of
100//! `materialize.com` will exclude requests to both `materialize.com` and
101//! `cloud.materialize.com` from proxying. For compatibility with other tools,
102//! domain names can include one optional `.` character at the start, which is
103//! ignored.
104//!
105//! Invalid entries in the list are silently ignored.
106//!
107//! If the `no_proxy` environment variable is set to the special value `*`, then
108//! all addresses will be excluded from proxying.
109//!
110//! ## See also
111//!
112//! For further details on these environment variables, see the GitLab blog
113//! article ["We need to talk: can we standardize NO_PROXY?"][gitlab-blog].
114//!
115//! [golang/go#16405]: https://github.com/golang/go/issues/16405
116//! [gitlab-blog]: https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/
117//! [Materialize]: https://materialize.com
118//! [repo]: https://github.com/MaterializeInc/materialize
119
120#[cfg(any(feature = "hyper", feature = "reqwest"))]
121mod proxy;
122
123#[cfg_attr(nightly_doc_features, doc(cfg(feature = "hyper")))]
124#[cfg(feature = "hyper")]
125pub mod hyper;
126
127#[cfg_attr(nightly_doc_features, doc(cfg(feature = "reqwest")))]
128#[cfg(feature = "reqwest")]
129pub mod reqwest;