///| test "parse_http_proxy_request rewrites GET request and strips leak/proxy headers" { let raw = b"GET http://stats.i2p/path?x=1 HTTP/1.1\r\nHost: stats.i2p\r\nProxy-Connection: keep-alive\r\nProxy-Authorization: Basic dXNlcjpwYXNz\r\nConnection: keep-alive\r\nKeep-Alive: timeout=5\r\nX-Forwarded-For: 1.2.3.4\r\nForwarded: for=1.2.3.4\r\nVia: 1.1 proxy\r\nReferer: https://google.com/search\r\nCookie: sid=xyz\r\nUser-Agent: TestBrowser/1.0\r\n\r\n" match parse_http_proxy_request(raw) { Ok(req) => { assert_eq(req.http_method, "GET") assert_eq(req.host, "stats.i2p") assert_eq(req.port, 80U) assert_eq(req.origin_path, "/path?x=1") assert_true(req.wire_headers.has_prefix("GET /path?x=1 HTTP/1.1\r\n")) assert_true(req.wire_headers.contains("Host: stats.i2p\r\n")) assert_true(req.wire_headers.contains("Cookie: sid=xyz\r\n")) assert_true( req.wire_headers.contains("User-Agent: MYOB/6.66 (AN/ON)\r\n"), ) assert_true(!req.wire_headers.contains("TestBrowser/1.0")) assert_true(req.wire_headers.has_suffix("Connection: close\r\n\r\n")) assert_true(!req.wire_headers.contains("Proxy-Connection")) assert_true(!req.wire_headers.contains("Proxy-Authorization")) assert_true(!req.wire_headers.contains("Keep-Alive")) assert_true(!req.wire_headers.contains("X-Forwarded-For")) assert_true(!req.wire_headers.contains("Forwarded:")) assert_true(!req.wire_headers.contains("Via:")) assert_true(!req.wire_headers.contains("google.com")) } Error(code, _, detail) => fail("unexpected error \{code}: \{detail}") } } ///| test "parse_http_proxy_request preserves POST headers, port, and .i2p Referer" { let raw = b"POST http://tracker2.postman.i2p:8080/?action=Enter HTTP/1.1\r\nHost: tracker2.postman.i2p:8080\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 42\r\nReferer: http://tracker2.postman.i2p/index.php\r\n\r\n" match parse_http_proxy_request(raw) { Ok(req) => { assert_eq(req.http_method, "POST") assert_eq(req.host, "tracker2.postman.i2p") assert_eq(req.port, 8080U) assert_eq(req.origin_path, "/?action=Enter") assert_true( req.wire_headers.contains( "Content-Type: application/x-www-form-urlencoded\r\n", ), ) assert_true(req.wire_headers.contains("Content-Length: 42\r\n")) assert_true( req.wire_headers.contains( "Referer: http://tracker2.postman.i2p/index.php\r\n", ), ) } Error(code, _, detail) => fail("unexpected error \{code}: \{detail}") } } ///| test "parse_http_proxy_request blocks clearnet hosts with 403 and CONNECT/https with 501" { match parse_http_proxy_request( b"GET http://example.com/secret HTTP/1.1\r\nHost: example.com\r\n\r\n", ) { Ok(_) => fail("expected 403 for clearnet host") Error(code, _, _) => assert_eq(code, 403) } match parse_http_proxy_request( b"CONNECT stats.i2p:443 HTTP/1.1\r\nHost: stats.i2p:443\r\n\r\n", ) { Ok(_) => fail("expected 501 for CONNECT") Error(code, _, _) => assert_eq(code, 501) } match parse_http_proxy_request( b"GET https://stats.i2p/ HTTP/1.1\r\nHost: stats.i2p\r\n\r\n", ) { Ok(_) => fail("expected 501 for https://") Error(code, _, _) => assert_eq(code, 501) } } ///| test "parse_http_proxy_request extracts i2paddresshelper and builds clean redirect URL" { match parse_http_proxy_request( b"GET http://newsite.i2p/?i2paddresshelper=TESTB64DATA~- HTTP/1.1\r\nHost: newsite.i2p\r\n\r\n", ) { Ok(req) => { assert_eq(req.helper_dest_b64, Some("TESTB64DATA~-")) assert_eq(req.clean_redirect_url, Some("http://newsite.i2p/")) } Error(code, _, detail) => fail("unexpected error \{code}: \{detail}") } match parse_http_proxy_request( b"GET http://newsite.i2p/dir?a=1&i2paddresshelper=ABC%7E1&b=2 HTTP/1.1\r\nHost: newsite.i2p\r\n\r\n", ) { Ok(req) => { assert_eq(req.helper_dest_b64, Some("ABC~1")) assert_eq(req.clean_redirect_url, Some("http://newsite.i2p/dir?a=1&b=2")) } Error(code, _, detail) => fail("unexpected error \{code}: \{detail}") } }