Rewriting CONNECT header

Madhu <[email protected]> Fri, 23 Feb 2024 17:52:48 +0530 (IST)
Newsgroups gmane.comp.web.privoxy.user
Message-ID <[email protected]>
Hello, Assume example.com resolves to 192.168.20.10 and there is a
https server running there, with adequately lax old-style SNI so that
this works:

     curl -4 --head https://192.168.20.10 -H 'Host: example.com'

I'm trying to see if I can get privoxy to do the rewrites so the
following works the same way:

    curl -4 -x localhost:8118 https://example.com/


``` use.filter
CLIENT-HEADER-FILTER: use-ip-for-example-com
s@^(HEAD|GET|POST) /([^ ]*) (HTTP/.*)$@$1 https://192.168.20.10/$2 $3@i
s@^(CONNECT)\s*example.com(.*)$@$1 192.168.20.10@i
# the following line should not be required because curl should set it.
#s@^(Host:) .*@$1 example.com:443@i
```

```user.actions
{+https-inspection}
example.com
192.168.20.10
{+ignore-certificate-errors}
example.com
192.168.20.10
{  +https-inspection +client-header-filter{use-ip-for-example} }
example.com/
```

However this does not seem to work. The (doctored) log is along these lines

```
 Re-Filter: filtering 'CONNECT example.com:443 HTTP/1.1' (size) with 'use-ip-for-example' ...
 Header: Transforming "CONNECT example.com:443 HTTP/1.1" to "CONNECT 192.168.20.10:443 HTTP/1.1"
 Re-Filter: ... produced 1 hits (new size).
 Re-Filter: filtering 'Host: example.com:443' (size) with 'use-ip-for-example' ...
 Re-Filter: ... produced 0 hits (new size).
 Re-Filter: filtering 'User-Agent: Mozilla/5.0 ()' (size) with 'use-ip-for-example' ...
 Re-Filter: ... produced 0 hits (new size).
 Redirect: Rewrite detected: CONNECT 192.168.20.10:443 HTTP/1.1
 Connect: Closing client socket 4. Keep-alive: 0. Socket alive: 1. Data available: 1. Configuration file change detected: 0. Requests received: 1.
```

and curl gets an EOF reply.

I'd appreciate any suggestions on what I ought to be trying. --Regards, Madhu