| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| library fuchsia.web; |
| |
| using fuchsia.net.http; |
| |
| type UrlRequestRewriteRule = table { |
| /// Set of hosts to apply the rules to. If not set, the rule will apply to every request, |
| /// independent of host. |
| 1: hosts_filter vector<UrlHostName>:MAX_RULE_COUNT; |
| |
| /// Set of schemes to apply the rules to. If not set, the rule will apply to every request, |
| /// independent of scheme. |
| 2: schemes_filter vector<UrlSchemeName>:MAX_RULE_COUNT; |
| |
| /// URL request rewrites to apply. |
| 3: rewrites vector<UrlRequestRewrite>:MAX_RULE_COUNT; |
| |
| /// Specifies the action to take for requests matching the filter criteria. |
| /// Requests are allowed by default. |
| 4: action UrlRequestAction; |
| }; |
| |
| type UrlRequestAction = strict enum : int32 { |
| /// Allow the request to be processed. |
| ALLOW = 1; |
| |
| /// Block the request. |
| DENY = 2; |
| }; |
| |
| type UrlRequestRewrite = flexible union { |
| /// Adds a set of headers to a URL request. |
| 1: add_headers UrlRequestRewriteAddHeaders; |
| |
| /// Removes a header based on the presence of a pattern in the URL query. |
| 2: remove_header UrlRequestRewriteRemoveHeader; |
| |
| /// Substitutes a pattern in the URL query. |
| 3: substitute_query_pattern UrlRequestRewriteSubstituteQueryPattern; |
| |
| /// Replaces a URL if the original URL ends with a pattern. |
| 4: replace_url UrlRequestRewriteReplaceUrl; |
| |
| /// Appends to the URL query. |
| 5: append_to_query UrlRequestRewriteAppendToQuery; |
| }; |
| |
| /// Adds `headers` to the URL request. If a header is already present in the original URL request, |
| /// it will be overwritten. |
| /// - `headers` must be set. |
| /// - Each [`fuchsia.net.http/Header`] in `headers` must have a valid HTTP header name and value, |
| /// per [RFC 7230 section 3.2](https://tools.ietf.org/html/rfc7230#section-3.2). |
| type UrlRequestRewriteAddHeaders = table { |
| 1: headers vector<fuchsia.net.http.Header>:MAX_HEADERS_COUNT; |
| }; |
| |
| /// If `query_pattern` in the URL query, removes `header_name` from the list of headers. If |
| /// `query_pattern` is not set, removes `header_name` from the list of headers unconditionally. |
| /// - `header_name` must be set. |
| /// - `header_name` must be a valid HTTP header name, per |
| /// [RFC 7230 section 3.2](https://tools.ietf.org/html/rfc7230#section-3.2). |
| type UrlRequestRewriteRemoveHeader = table { |
| 1: query_pattern Url; |
| 2: header_name bytes:MAX_HEADERS_COUNT; |
| }; |
| |
| /// If `pattern` is found in the URL request query, replaces it with `substitution`. |
| /// - `pattern` and `substitution` must be set. |
| /// - `substitution` must be a valid |
| /// [URL-query string](https://url.spec.whatwg.org/#url-query-string). |
| type UrlRequestRewriteSubstituteQueryPattern = table { |
| 1: pattern Url; |
| 2: substitution Url; |
| }; |
| |
| /// If the URL in the URL request ends with `url_ends_with`, rewrites the URL to `new_url`. |
| /// - `url_ends_with` and `new_url` must be set. |
| /// - `url_ends_with` must be a valid |
| /// [path-relative-URL string](https://url.spec.whatwg.org/#path-relative-url-string). |
| /// - `new_url` must be a [valid URL string](https://url.spec.whatwg.org/#valid-url-string). |
| type UrlRequestRewriteReplaceUrl = table { |
| 1: url_ends_with Url; |
| 2: new_url Url; |
| }; |
| |
| /// Appends `query` to the URL query. If the URL request already has a query, `query` will be |
| /// appended to it, preceded by `&`. Otherwise, the URL's query will be set to `query`. |
| /// - `query` must be set. |
| /// - `query` must be a valid [URL-query string](https://url.spec.whatwg.org/#url-query-string). |
| type UrlRequestRewriteAppendToQuery = table { |
| 1: query Url; |
| }; |