Header Rewrite
Chute can rewrite request and response headers before they are forwarded to the server or client.
Mutiple rules could be applied for one single request.
Notice: A plain HTTP request is processed only when it reaches Chute through its HTTP proxy; plain HTTP that arrives through the TUN interface is forwarded untouched. Chute Android sends all traffic through TUN unless System HTTP Proxy is turned on in Settings, which hands apps Chute's HTTP proxy (Android 10 and later; off by default). An HTTPS request is processed only when its host is decrypted with MitM.
Example:
[Header Rewrite]
^http://example\.com.* header-add DNT 1
^http://example\.com.* header-del Cookie
^http://example\.com.* header-replace User-Agent Unknown
^http://example\.com.* header-response-add X-Server rack3
^http://example\.com.* header-response-del X-Powered-By
^http://example\.com.* header-response-replace Server nginx
The rewrite rule consists 4 parts: URL regular expression, action type, header field and value. Only a // at the start of the line or after a space, outside double quotes, begins a comment here; # and ; never do, so header-add X-Color #ff0000 keeps its value. See Comment.
Notice: The URL regular expression is matched anywhere in the request's full URL, and in its path alone, as in URL Rewrite:
^https://example\.comalready covers every path and query string under that host, so a trailing.*is unnecessary, and^/apimatches every request whose path starts with/api. The full URL of a decrypted request starts withhttps://, so a^http://pattern never matches one. The pattern keeps its case, so\S,\D,\Wand\Bmean what they say; the match itself ignores case.
Request vs Response Headers
Actions prefixed with header- apply to request headers (from client to server). Actions prefixed with header-response- apply to response headers (from server to client).
An optional Surge-style direction prefix http-request / http-response placed before the URL regular expression is also accepted, e.g. http-request ^http://example\.com.* header-replace Accept-Language en-us.
header-add
Set a header field in the request header to the given value. If the header field already exists, it is overwritten; a field with several lines is left with the one new line.
Example:
[Header Rewrite]
^http://example\.com.* header-add DNT 1
Before:
GET /index.html HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30
Accept-Language: en-us
Accept-Encoding: gzip, deflate
After:
GET /index.html HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30
Accept-Language: en-us
Accept-Encoding: gzip, deflate
DNT: 1
header-del
Delete a header field from the request header, with all of its lines when it has several.
Example:
[Header Rewrite]
^http://example\.com.* header-del DNT
Before:
GET /index.html HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30
Accept-Language: en-us
Accept-Encoding: gzip, deflate
DNT: 1
After:
GET /index.html HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30
Accept-Language: en-us
Accept-Encoding: gzip, deflate
header-replace
Replace a header value in the request header. If the header field doesn't exist, nothing happens. A field with several lines is left with one line holding the new value.
Example:
[Header Rewrite]
^http://example\.com.* header-replace DNT 1
Before:
GET /index.html HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30
Accept-Language: en-us
Accept-Encoding: gzip, deflate
DNT: 0
After:
GET /index.html HTTP/1.1
Host: example.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30
Accept-Language: en-us
Accept-Encoding: gzip, deflate
DNT: 1
Notice:
header-replaceonly works when the header field already exists. To set a header field regardless of whether it exists, useheader-add— it overwrites any existing field with the same name, so combiningheader-delandheader-addis unnecessary.
header-replace-regex
Rewrite part of an existing header value with a regular expression. The rule takes the header field, a regular expression applied to its value, and the replacement, which may refer to capture groups as $1, $2. Nothing happens when the header field does not exist. Quote the regular expression or the replacement with double quotes when it contains spaces; "" is an empty replacement.
Example:
[Header Rewrite]
^https://example\.com header-replace-regex User-Agent "Chrome/[0-9.]+" Chrome/120.0.0.0
^https://example\.com header-response-replace-regex Set-Cookie "; Secure" ""
The regular expression applied to the header value is case-sensitive. A field with several lines, such as the Set-Cookie lines of a response, has each line rewritten on its own, and all of them are kept. As with the other actions, header-response-replace-regex (or the http-response prefix) works on response headers.