From 9f6d13c7b520af0150956945d1c5d3cbb0ee529c Mon Sep 17 00:00:00 2001 From: Sneha S Biju Date: Sun, 22 Mar 2026 17:02:39 +0000 Subject: [PATCH 1/3] feat: add HTTP caching for PAC fetch using httpcache (RFC 9111 compliant) --- blocklist_test.go | 6 +- ...c6536d3d17bd596741d98fde544020a664e61f0bee | 9 +++ ...49fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 | 9 +++ ...c504987316efb692c524d4dd35b20fd1f0492257f2 | 9 +++ ...068e6f36fb769046991baa137b7c412968d27e66f4 | 9 +++ ...d3574042011b3151afd101f10edb288ea7649bd2f5 | 9 +++ ...3baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 | 9 +++ ...ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 | 9 +++ ...7f20cb9b527c128a57439cab2657d8f1a1dba87545 | 9 +++ ...f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb | 9 +++ ...dafe6127fada0536749d7a820559af1b4e56d742cc | 9 +++ ...2b9159ac2645db9597b9897dce91ee47a2b1d063e8 | 9 +++ ...04305c8196de304e02df02406db3e78ffa679e9d0a | 9 +++ ...1c33a6fca382a5976985b3d31ec2205a7a55d4539f | 9 +++ ...d4e5a3a19c16f81490e576f006b497db1cc52cc3ce | 9 +++ ...7bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d | 9 +++ ...0011957f2ae8f5c3cd1225c7a567ecb05379c85327 | 9 +++ ...a044dad6e75eb1eed6c98a8578137dc70d611ff73c | 9 +++ ...f6ace13021bd143d4c43715107131d477a209d8d92 | 9 +++ ...6d71ec9cd5e48a82373e278e667cf693a6dc4f642c | 9 +++ ...07443923ab825ca5e13461110e666ce231c10d34f5 | 9 +++ ...3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 | 9 +++ ...d23836f6e312b29624b9cf933a3a44d7c767a7eb7f | 9 +++ ...2e7137323c188c10ce8552472300666e14047b6915 | 9 +++ ...f3b9c1377e05747b830186e46eade39294b5dd2a1f | 9 +++ ...376b41aa4dc50147328a0e319bafd1e248ef973afa | 9 +++ ...ffb141b12f8650d40fec098903d29ecb7ca088acb6 | 9 +++ ...ce2448d28c14e76d67bf88177f6f617ab0e71e24ef | 9 +++ ...c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 | 9 +++ ...129c5efa252f6cd96b6de732f94bd885ef3da2fd0f | 9 +++ ...f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e | 9 +++ go.mod | 17 ++--- go.sum | 26 ++++--- main_test.go | 1 + pacfetcher.go | 69 ++++++++----------- pacfinder_windows.go | 2 +- transport_test.go | 6 +- 37 files changed, 331 insertions(+), 66 deletions(-) create mode 100644 cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee create mode 100644 cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 create mode 100644 cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 create mode 100644 cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 create mode 100644 cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 create mode 100644 cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 create mode 100644 cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 create mode 100644 cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 create mode 100644 cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb create mode 100644 cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc create mode 100644 cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 create mode 100644 cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a create mode 100644 cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f create mode 100644 cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce create mode 100644 cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d create mode 100644 cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 create mode 100644 cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c create mode 100644 cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 create mode 100644 cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c create mode 100644 cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 create mode 100644 cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 create mode 100644 cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f create mode 100644 cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 create mode 100644 cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f create mode 100644 cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa create mode 100644 cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 create mode 100644 cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef create mode 100644 cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 create mode 100644 cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f create mode 100644 cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e diff --git a/blocklist_test.go b/blocklist_test.go index ac4425a..642bcfb 100644 --- a/blocklist_test.go +++ b/blocklist_test.go @@ -49,10 +49,10 @@ func TestBlocklistDuplicateEntry(t *testing.T) { var now time.Time b.now = func() time.Time { return now } b.add("foo") - now = now.Add(3*time.Minute) + now = now.Add(3 * time.Minute) b.add("foo") - now = now.Add(3*time.Minute) + now = now.Add(3 * time.Minute) b.contains("foo") - now = now.Add(3*time.Minute) + now = now.Add(3 * time.Minute) b.contains("foo") } diff --git a/cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee b/cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee new file mode 100644 index 0000000..30f4931 --- /dev/null +++ b/cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 11 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:14 GMT +X-Cached-Time: 2026-03-22T16:54:14Z +X-Request-Time: 2026-03-22T16:54:14Z +X-Response-Time: 2026-03-22T16:54:14Z + +test script \ No newline at end of file diff --git a/cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 b/cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 new file mode 100644 index 0000000..29abd96 --- /dev/null +++ b/cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 82 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return "PROXY primary:80; PROXY backup:80" } \ No newline at end of file diff --git a/cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 b/cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 new file mode 100644 index 0000000..99f67fc --- /dev/null +++ b/cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 55 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'DIRECT' } \ No newline at end of file diff --git a/cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 b/cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 new file mode 100644 index 0000000..94db3ef --- /dev/null +++ b/cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 82 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return "PROXY primary:80; PROXY backup:80" } \ No newline at end of file diff --git a/cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 b/cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 new file mode 100644 index 0000000..886be76 --- /dev/null +++ b/cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 63 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'HTTP http.test' } \ No newline at end of file diff --git a/cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 b/cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 new file mode 100644 index 0000000..2e1e561 --- /dev/null +++ b/cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 11 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:15 GMT +X-Cached-Time: 2026-03-22T16:59:15Z +X-Request-Time: 2026-03-22T16:59:15Z +X-Response-Time: 2026-03-22T16:59:15Z + +test script \ No newline at end of file diff --git a/cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 b/cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 new file mode 100644 index 0000000..57ff339 --- /dev/null +++ b/cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 69 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'INVALID RETURN VALUE' } \ No newline at end of file diff --git a/cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 b/cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 new file mode 100644 index 0000000..e24e5d7 --- /dev/null +++ b/cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 13 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:15 GMT +X-Cached-Time: 2026-03-22T16:59:15Z +X-Request-Time: 2026-03-22T16:59:15Z +X-Response-Time: 2026-03-22T16:59:15Z + +test script 2 \ No newline at end of file diff --git a/cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb b/cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb new file mode 100644 index 0000000..200a33f --- /dev/null +++ b/cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 72 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'SOCKS socksproxy.test:3' } \ No newline at end of file diff --git a/cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc b/cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc new file mode 100644 index 0000000..ec0701e --- /dev/null +++ b/cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 65 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'HTTP http.test:4' } \ No newline at end of file diff --git a/cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 b/cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 new file mode 100644 index 0000000..c2a24f0 --- /dev/null +++ b/cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 72 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'SOCKS socksproxy.test:3' } \ No newline at end of file diff --git a/cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a b/cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a new file mode 100644 index 0000000..d90c240 --- /dev/null +++ b/cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 65 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'HTTPS https.test' } \ No newline at end of file diff --git a/cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f b/cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f new file mode 100644 index 0000000..30f4931 --- /dev/null +++ b/cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 11 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:14 GMT +X-Cached-Time: 2026-03-22T16:54:14Z +X-Request-Time: 2026-03-22T16:54:14Z +X-Response-Time: 2026-03-22T16:54:14Z + +test script \ No newline at end of file diff --git a/cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce b/cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce new file mode 100644 index 0000000..91d37e3 --- /dev/null +++ b/cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 65 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'PROXY proxy.test' } \ No newline at end of file diff --git a/cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d b/cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d new file mode 100644 index 0000000..44ae6d7 --- /dev/null +++ b/cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 67 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'HTTPS https.test:5' } \ No newline at end of file diff --git a/cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 b/cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 new file mode 100644 index 0000000..2e1e561 --- /dev/null +++ b/cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 11 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:15 GMT +X-Cached-Time: 2026-03-22T16:59:15Z +X-Request-Time: 2026-03-22T16:59:15Z +X-Response-Time: 2026-03-22T16:59:15Z + +test script \ No newline at end of file diff --git a/cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c b/cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c new file mode 100644 index 0000000..491948a --- /dev/null +++ b/cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 65 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'PROXY proxy.test' } \ No newline at end of file diff --git a/cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 b/cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 new file mode 100644 index 0000000..d27db2e --- /dev/null +++ b/cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 55 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'DIRECT' } \ No newline at end of file diff --git a/cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c b/cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c new file mode 100644 index 0000000..5364370 --- /dev/null +++ b/cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 65 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'HTTP http.test:4' } \ No newline at end of file diff --git a/cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 b/cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 new file mode 100644 index 0000000..09844a7 --- /dev/null +++ b/cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 63 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'HTTP http.test' } \ No newline at end of file diff --git a/cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 b/cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 new file mode 100644 index 0000000..686fce8 --- /dev/null +++ b/cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 67 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'HTTPS https.test:5' } \ No newline at end of file diff --git a/cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f b/cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f new file mode 100644 index 0000000..aae31cf --- /dev/null +++ b/cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 75 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'PROXY proxy.test:1; DIRECT' } \ No newline at end of file diff --git a/cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 b/cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 new file mode 100644 index 0000000..96d1346 --- /dev/null +++ b/cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 67 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'PROXY proxy.test:2' } \ No newline at end of file diff --git a/cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f b/cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f new file mode 100644 index 0000000..935fbfa --- /dev/null +++ b/cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 69 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'INVALID RETURN VALUE' } \ No newline at end of file diff --git a/cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa b/cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa new file mode 100644 index 0000000..4695d6b --- /dev/null +++ b/cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 67 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { return 'PROXY proxy.test:2' } \ No newline at end of file diff --git a/cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 b/cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 new file mode 100644 index 0000000..9be23af --- /dev/null +++ b/cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 53 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:59:16 GMT +X-Cached-Time: 2026-03-22T16:59:16Z +X-Request-Time: 2026-03-22T16:59:16Z +X-Response-Time: 2026-03-22T16:59:16Z + +function FindProxyForURL(url, host) { throw 'error' } \ No newline at end of file diff --git a/cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef b/cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef new file mode 100644 index 0000000..a3060c2 --- /dev/null +++ b/cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 13 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:14 GMT +X-Cached-Time: 2026-03-22T16:54:14Z +X-Request-Time: 2026-03-22T16:54:14Z +X-Response-Time: 2026-03-22T16:54:14Z + +test script 2 \ No newline at end of file diff --git a/cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 b/cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 new file mode 100644 index 0000000..dbd4159 --- /dev/null +++ b/cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 75 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:14 GMT +X-Cached-Time: 2026-03-22T16:54:14Z +X-Request-Time: 2026-03-22T16:54:14Z +X-Response-Time: 2026-03-22T16:54:14Z + +function FindProxyForURL(url, host) { return 'PROXY proxy.test:1; DIRECT' } \ No newline at end of file diff --git a/cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f b/cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f new file mode 100644 index 0000000..02a0cd5 --- /dev/null +++ b/cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 53 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:14 GMT +X-Cached-Time: 2026-03-22T16:54:14Z +X-Request-Time: 2026-03-22T16:54:14Z +X-Response-Time: 2026-03-22T16:54:14Z + +function FindProxyForURL(url, host) { throw 'error' } \ No newline at end of file diff --git a/cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e b/cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e new file mode 100644 index 0000000..b7349f9 --- /dev/null +++ b/cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e @@ -0,0 +1,9 @@ +HTTP/1.1 200 OK +Content-Length: 65 +Content-Type: text/plain; charset=utf-8 +Date: Sun, 22 Mar 2026 16:54:15 GMT +X-Cached-Time: 2026-03-22T16:54:15Z +X-Request-Time: 2026-03-22T16:54:15Z +X-Response-Time: 2026-03-22T16:54:15Z + +function FindProxyForURL(url, host) { return 'HTTPS https.test' } \ No newline at end of file diff --git a/go.mod b/go.mod index 09b11da..b94a153 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,16 @@ module github.com/samuong/alpaca/v2 -go 1.22.3 - -toolchain go1.22.4 +go 1.25.3 require ( github.com/gobwas/glob v0.2.3 github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6 github.com/robertkrimen/otto v0.4.0 github.com/samuong/go-ntlmssp v0.0.0-20240616070040-65a20607c744 - github.com/stretchr/testify v1.9.0 + github.com/sandrolain/httpcache v1.4.0 + github.com/stretchr/testify v1.11.1 github.com/zalando/go-keyring v0.2.5 - golang.org/x/term v0.21.0 + golang.org/x/term v0.36.0 ) require ( @@ -19,10 +18,12 @@ require ( github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/google/btree v1.1.3 // indirect + github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.24.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/crypto v0.43.0 // indirect + golang.org/x/sys v0.37.0 // indirect + golang.org/x/text v0.30.0 // indirect gopkg.in/sourcemap.v1 v1.0.5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 9e3d582..5de0c17 100644 --- a/go.sum +++ b/go.sum @@ -8,28 +8,34 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= +github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6 h1:IsMZxCuZqKuao2vNdfD82fjjgPLfyHLpR41Z88viRWs= github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6/go.mod h1:3VeWNIJaW+O5xpRQbPp0Ybqu1vJd/pm7s2F473HRrkw= +github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= +github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/robertkrimen/otto v0.4.0 h1:/c0GRrK1XDPcgIasAsnlpBT5DelIeB9U/Z/JCQsgr7E= github.com/robertkrimen/otto v0.4.0/go.mod h1:uW9yN1CYflmUQYvAMS0m+ZiNo3dMzRUDQJX0jWbzgxw= github.com/samuong/go-ntlmssp v0.0.0-20240616070040-65a20607c744 h1:AD1UeK7fZRLY7TEeQQZNTuHX3RAspwLUC36mNi47Xcs= github.com/samuong/go-ntlmssp v0.0.0-20240616070040-65a20607c744/go.mod h1:ioghl8+axI3Mx5Cs1LU/LzW18JE71qbwXwpOv/F9lCc= +github.com/sandrolain/httpcache v1.4.0 h1:Jf4Vx62X2ybvNPSpPvI1kT3xvMdDG1AsApQjOQKO9E0= +github.com/sandrolain/httpcache v1.4.0/go.mod h1:kHBuXveitSn39SNPBhdf/ybG272X706HJ2RJqOQ+Em0= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/zalando/go-keyring v0.2.5 h1:Bc2HHpjALryKD62ppdEzaFG6VxL6Bc+5v0LYpN8Lba8= github.com/zalando/go-keyring v0.2.5/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= +golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= +golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= +golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= +golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI= diff --git a/main_test.go b/main_test.go index 3ff9cd1..e685473 100644 --- a/main_test.go +++ b/main_test.go @@ -17,6 +17,7 @@ // machines. So the tests in this file are disabled by default using a build // constraint, and need to be run using `go test ./... -tags=squid`. +//go:build squid // +build squid package main diff --git a/pacfetcher.go b/pacfetcher.go index 723e286..d115124 100644 --- a/pacfetcher.go +++ b/pacfetcher.go @@ -1,16 +1,7 @@ // Copyright 2019, 2021, 2022, 2025 The Alpaca Authors // // Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// ... package main @@ -25,18 +16,14 @@ import ( "runtime" "strings" "time" + + "github.com/sandrolain/httpcache" + "github.com/sandrolain/httpcache/diskcache" ) -// The maximum size (in bytes) allowed for a PAC script. At 1 MB, this matches the limit in Chrome. const maxResponseBytes = 1 * 1024 * 1024 - -// The maximum size (in bytes) allowed for a data URL. -// Chromium and Firefox limit data URLs to 512MB. -// See https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data#length_limitations const maxDataURLLength = 512 * 1024 * 1024 -// The time to wait before retrying a failed PAC download. This is similar to Chrome's delay: -// https://cs.chromium.org/chromium/src/net/proxy_resolution/proxy_resolution_service.cc?l=96&rcl=3db5f65968c3ecab3932c1ff7367ad28834f9502 var delayAfterFailedDownload = 2 * time.Second type pacFetcher struct { @@ -44,31 +31,38 @@ type pacFetcher struct { monitor netMonitor client *http.Client connected bool - //cache []byte - //modified time.Time - //fetched time.Time - //expiry time.Time - //etag string } func newPACFetcher(pacurl string) *pacFetcher { - client := &http.Client{Timeout: 30 * time.Second} + var client *http.Client + if strings.HasPrefix(pacurl, "file:") { log.Print("Warning: When using a local PAC file, the online/offline status can't ", "be determined by the fact that the PAC file is downloaded. Make sure you ", "check for proxy connectivity in your PAC file!") + + client = &http.Client{Timeout: 30 * time.Second} + if runtime.GOOS == "windows" { client.Transport = http.NewFileTransport(http.Dir("C:")) } else { client.Transport = http.NewFileTransport(http.Dir("/")) } + } else { - // The DefaultClient in net/http uses the proxy specified in the http(s)_proxy - // environment variable, which could be pointing at this instance of alpaca. When - // fetching the PAC file, we always use a client that goes directly to the server, - // rather than via a proxy. - client.Transport = &http.Transport{Proxy: nil} + // Base transport without proxy (important: avoid proxy loop) + baseTransport := &http.Transport{Proxy: nil} + + // Add HTTP caching + cacheTransport := httpcache.NewTransport(diskcache.New("cache")) + cacheTransport.Transport = baseTransport + + client = &http.Client{ + Timeout: 30 * time.Second, + Transport: cacheTransport, + } } + return &pacFetcher{ pacFinder: newPacFinder(pacurl), monitor: newNetMonitor(), @@ -87,12 +81,8 @@ func requireOK(resp *http.Response, err error) (*http.Response, error) { } } -// decodeDataURL decodes a data URL (e.g., data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==). -// It supports both base64 and URL-encoded data, and enforces the maxResponseBytes size limit. -// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs for details. func decodeDataURL(uri string) ([]byte, error) { parsedURL, err := url.Parse(uri) - if err != nil { return nil, fmt.Errorf("error parsing pac url: %w", err) } @@ -127,17 +117,11 @@ func decodeDataURL(uri string) ([]byte, error) { } func (pf *pacFetcher) download() []byte { - // TODO: Combine pacChanged() and findPACURL() as described in - // https://github.com/samuong/alpaca/pull/156#issuecomment-3125070335 if !pf.monitor.addrsChanged() && !pf.pacFinder.pacChanged() { return nil } pf.connected = false - // We've just detected a change in network state, so close any "idle" - // connections from the previous network. This forces a fresh DNS - // lookup and TCP dial during the next PAC download. For context, see - // . pf.client.CloseIdleConnections() pacurl, err := pf.pacFinder.findPACURL() @@ -162,19 +146,22 @@ func (pf *pacFetcher) download() []byte { return pac } + // Cached HTTP request (handled automatically by transport) resp, err := requireOK(pf.client.Get(pacurl)) if err != nil { - // Sometimes, if we try to download too soon after a network change, the PAC - // download can fail. See https://github.com/samuong/alpaca/issues/8 for details. log.Printf("Error downloading PAC file, will retry after %v: %q", delayAfterFailedDownload, err) + time.Sleep(delayAfterFailedDownload) + + // Retry once if resp, err = requireOK(pf.client.Get(pacurl)); err != nil { log.Printf("Error downloading PAC file, giving up: %q", err) - return nil + return nil // ❗ No fallback to cached PAC (correct behavior) } } defer resp.Body.Close() + var buf bytes.Buffer _, err = io.CopyN(&buf, resp.Body, maxResponseBytes) if err == io.EOF { diff --git a/pacfinder_windows.go b/pacfinder_windows.go index ed141d2..6fedc07 100644 --- a/pacfinder_windows.go +++ b/pacfinder_windows.go @@ -14,7 +14,7 @@ package main -type pacFinder struct{ +type pacFinder struct { pacURL string } diff --git a/transport_test.go b/transport_test.go index 04d0f6a..8ea31d1 100644 --- a/transport_test.go +++ b/transport_test.go @@ -69,18 +69,18 @@ func TestTransportErrors(t *testing.T) { req, err := http.NewRequest(http.MethodGet, "http://alpaca.test", nil) require.NoError(t, err) - t.Run("NotConnected", func (t *testing.T) { + t.Run("NotConnected", func(t *testing.T) { _, err = tr.RoundTrip(req) assert.Error(t, err) }) - t.Run("Closed", func (t *testing.T) { + t.Run("Closed", func(t *testing.T) { require.NoError(t, tr.Close()) _, err = tr.RoundTrip(req) assert.Error(t, err) }) - t.Run("CloseTwice", func (t *testing.T) { + t.Run("CloseTwice", func(t *testing.T) { assert.NoError(t, tr.Close()) assert.NoError(t, tr.Close()) }) From 63a249b1722a45c405fb7d509114feb7c459f858 Mon Sep 17 00:00:00 2001 From: Sneha S Biju Date: Wed, 25 Mar 2026 00:33:28 +0000 Subject: [PATCH 2/3] fix: use in-memory cache, restore comments, add test for no cache fallback --- .gitignore | 1 + ...c6536d3d17bd596741d98fde544020a664e61f0bee | 9 ------- ...49fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 | 9 ------- ...c504987316efb692c524d4dd35b20fd1f0492257f2 | 9 ------- ...068e6f36fb769046991baa137b7c412968d27e66f4 | 9 ------- ...d3574042011b3151afd101f10edb288ea7649bd2f5 | 9 ------- ...3baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 | 9 ------- ...ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 | 9 ------- ...7f20cb9b527c128a57439cab2657d8f1a1dba87545 | 9 ------- ...f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb | 9 ------- ...dafe6127fada0536749d7a820559af1b4e56d742cc | 9 ------- ...2b9159ac2645db9597b9897dce91ee47a2b1d063e8 | 9 ------- ...04305c8196de304e02df02406db3e78ffa679e9d0a | 9 ------- ...1c33a6fca382a5976985b3d31ec2205a7a55d4539f | 9 ------- ...d4e5a3a19c16f81490e576f006b497db1cc52cc3ce | 9 ------- ...7bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d | 9 ------- ...0011957f2ae8f5c3cd1225c7a567ecb05379c85327 | 9 ------- ...a044dad6e75eb1eed6c98a8578137dc70d611ff73c | 9 ------- ...f6ace13021bd143d4c43715107131d477a209d8d92 | 9 ------- ...6d71ec9cd5e48a82373e278e667cf693a6dc4f642c | 9 ------- ...07443923ab825ca5e13461110e666ce231c10d34f5 | 9 ------- ...3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 | 9 ------- ...d23836f6e312b29624b9cf933a3a44d7c767a7eb7f | 9 ------- ...2e7137323c188c10ce8552472300666e14047b6915 | 9 ------- ...f3b9c1377e05747b830186e46eade39294b5dd2a1f | 9 ------- ...376b41aa4dc50147328a0e319bafd1e248ef973afa | 9 ------- ...ffb141b12f8650d40fec098903d29ecb7ca088acb6 | 9 ------- ...ce2448d28c14e76d67bf88177f6f617ab0e71e24ef | 9 ------- ...c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 | 9 ------- ...129c5efa252f6cd96b6de732f94bd885ef3da2fd0f | 9 ------- ...f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e | 9 ------- pacfetcher.go | 11 +++----- pacfetcher_cache_test.go | 27 +++++++++++++++++++ pacfinder_darwin_test.go | 2 +- 34 files changed, 33 insertions(+), 278 deletions(-) delete mode 100644 cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee delete mode 100644 cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 delete mode 100644 cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 delete mode 100644 cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 delete mode 100644 cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 delete mode 100644 cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 delete mode 100644 cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 delete mode 100644 cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 delete mode 100644 cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb delete mode 100644 cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc delete mode 100644 cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 delete mode 100644 cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a delete mode 100644 cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f delete mode 100644 cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce delete mode 100644 cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d delete mode 100644 cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 delete mode 100644 cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c delete mode 100644 cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 delete mode 100644 cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c delete mode 100644 cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 delete mode 100644 cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 delete mode 100644 cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f delete mode 100644 cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 delete mode 100644 cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f delete mode 100644 cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa delete mode 100644 cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 delete mode 100644 cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef delete mode 100644 cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 delete mode 100644 cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f delete mode 100644 cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e create mode 100644 pacfetcher_cache_test.go diff --git a/.gitignore b/.gitignore index 03c657a..77762e5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __debug_bin* .idea .DS_Store +cache/ diff --git a/cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee b/cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee deleted file mode 100644 index 30f4931..0000000 --- a/cache/0716f3ab870e959af20406c6536d3d17bd596741d98fde544020a664e61f0bee +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 11 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:14 GMT -X-Cached-Time: 2026-03-22T16:54:14Z -X-Request-Time: 2026-03-22T16:54:14Z -X-Response-Time: 2026-03-22T16:54:14Z - -test script \ No newline at end of file diff --git a/cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 b/cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 deleted file mode 100644 index 29abd96..0000000 --- a/cache/074e5a0e00e010a2d81ea649fc5af4d7096f84fc9ffbb0eb4555f3d027da0522 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 82 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return "PROXY primary:80; PROXY backup:80" } \ No newline at end of file diff --git a/cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 b/cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 deleted file mode 100644 index 99f67fc..0000000 --- a/cache/15b10d57edada9c4a5b5ddc504987316efb692c524d4dd35b20fd1f0492257f2 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 55 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'DIRECT' } \ No newline at end of file diff --git a/cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 b/cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 deleted file mode 100644 index 94db3ef..0000000 --- a/cache/18cb3815cbdd992ef2820b068e6f36fb769046991baa137b7c412968d27e66f4 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 82 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return "PROXY primary:80; PROXY backup:80" } \ No newline at end of file diff --git a/cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 b/cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 deleted file mode 100644 index 886be76..0000000 --- a/cache/20fbf45e880549fbffb4f8d3574042011b3151afd101f10edb288ea7649bd2f5 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 63 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'HTTP http.test' } \ No newline at end of file diff --git a/cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 b/cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 deleted file mode 100644 index 2e1e561..0000000 --- a/cache/2a9f4090ba4831a55edf223baa34cb0b7bbd3d8c244cb0ff7f5d4e1589f5a872 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 11 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:15 GMT -X-Cached-Time: 2026-03-22T16:59:15Z -X-Request-Time: 2026-03-22T16:59:15Z -X-Response-Time: 2026-03-22T16:59:15Z - -test script \ No newline at end of file diff --git a/cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 b/cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 deleted file mode 100644 index 57ff339..0000000 --- a/cache/31a27abdf1945ccca5ca30ad075b1cbbbda7ed8e9ca0ac881f02e4b2419f30c1 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 69 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'INVALID RETURN VALUE' } \ No newline at end of file diff --git a/cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 b/cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 deleted file mode 100644 index e24e5d7..0000000 --- a/cache/44be16e46a43d423465a067f20cb9b527c128a57439cab2657d8f1a1dba87545 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 13 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:15 GMT -X-Cached-Time: 2026-03-22T16:59:15Z -X-Request-Time: 2026-03-22T16:59:15Z -X-Response-Time: 2026-03-22T16:59:15Z - -test script 2 \ No newline at end of file diff --git a/cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb b/cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb deleted file mode 100644 index 200a33f..0000000 --- a/cache/55f99a8adc533969548ea2f6ea09517bb10094147f1d95d8cc0b0b110a7a37fb +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 72 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'SOCKS socksproxy.test:3' } \ No newline at end of file diff --git a/cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc b/cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc deleted file mode 100644 index ec0701e..0000000 --- a/cache/55feb950dc833672a030dddafe6127fada0536749d7a820559af1b4e56d742cc +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 65 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'HTTP http.test:4' } \ No newline at end of file diff --git a/cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 b/cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 deleted file mode 100644 index c2a24f0..0000000 --- a/cache/5b5ceeee8a772dc07c0ccb2b9159ac2645db9597b9897dce91ee47a2b1d063e8 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 72 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'SOCKS socksproxy.test:3' } \ No newline at end of file diff --git a/cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a b/cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a deleted file mode 100644 index d90c240..0000000 --- a/cache/5fd83d919248b288f0abd304305c8196de304e02df02406db3e78ffa679e9d0a +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 65 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'HTTPS https.test' } \ No newline at end of file diff --git a/cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f b/cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f deleted file mode 100644 index 30f4931..0000000 --- a/cache/60277959754a368c77d7321c33a6fca382a5976985b3d31ec2205a7a55d4539f +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 11 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:14 GMT -X-Cached-Time: 2026-03-22T16:54:14Z -X-Request-Time: 2026-03-22T16:54:14Z -X-Response-Time: 2026-03-22T16:54:14Z - -test script \ No newline at end of file diff --git a/cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce b/cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce deleted file mode 100644 index 91d37e3..0000000 --- a/cache/63d271dadd7e8ddb9a67e8d4e5a3a19c16f81490e576f006b497db1cc52cc3ce +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 65 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'PROXY proxy.test' } \ No newline at end of file diff --git a/cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d b/cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d deleted file mode 100644 index 44ae6d7..0000000 --- a/cache/800e722d8032e0be2423f37bf8642ba4a8d3365cb9a2f2ef410959fff2f2db0d +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 67 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'HTTPS https.test:5' } \ No newline at end of file diff --git a/cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 b/cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 deleted file mode 100644 index 2e1e561..0000000 --- a/cache/8d3d144c7b2218faef294a0011957f2ae8f5c3cd1225c7a567ecb05379c85327 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 11 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:15 GMT -X-Cached-Time: 2026-03-22T16:59:15Z -X-Request-Time: 2026-03-22T16:59:15Z -X-Response-Time: 2026-03-22T16:59:15Z - -test script \ No newline at end of file diff --git a/cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c b/cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c deleted file mode 100644 index 491948a..0000000 --- a/cache/8e9ccc650f849447ed6bcea044dad6e75eb1eed6c98a8578137dc70d611ff73c +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 65 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'PROXY proxy.test' } \ No newline at end of file diff --git a/cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 b/cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 deleted file mode 100644 index d27db2e..0000000 --- a/cache/961e3f7d3b00fac3cee4d9f6ace13021bd143d4c43715107131d477a209d8d92 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 55 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'DIRECT' } \ No newline at end of file diff --git a/cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c b/cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c deleted file mode 100644 index 5364370..0000000 --- a/cache/97828ecddaf34856f751396d71ec9cd5e48a82373e278e667cf693a6dc4f642c +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 65 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'HTTP http.test:4' } \ No newline at end of file diff --git a/cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 b/cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 deleted file mode 100644 index 09844a7..0000000 --- a/cache/a834bbd32367a0265f0d4f07443923ab825ca5e13461110e666ce231c10d34f5 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 63 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'HTTP http.test' } \ No newline at end of file diff --git a/cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 b/cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 deleted file mode 100644 index 686fce8..0000000 --- a/cache/b8fdfed15fc3f345f5a44d3fd38b251ea61ace6df9dd74b16ec011f4ef91fb64 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 67 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'HTTPS https.test:5' } \ No newline at end of file diff --git a/cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f b/cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f deleted file mode 100644 index aae31cf..0000000 --- a/cache/b9ae80258cc064d16ba6fbd23836f6e312b29624b9cf933a3a44d7c767a7eb7f +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 75 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'PROXY proxy.test:1; DIRECT' } \ No newline at end of file diff --git a/cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 b/cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 deleted file mode 100644 index 96d1346..0000000 --- a/cache/c53487273bc3f145588b962e7137323c188c10ce8552472300666e14047b6915 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 67 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'PROXY proxy.test:2' } \ No newline at end of file diff --git a/cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f b/cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f deleted file mode 100644 index 935fbfa..0000000 --- a/cache/c7f5a30214880547d5c84ff3b9c1377e05747b830186e46eade39294b5dd2a1f +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 69 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'INVALID RETURN VALUE' } \ No newline at end of file diff --git a/cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa b/cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa deleted file mode 100644 index 4695d6b..0000000 --- a/cache/ce85a99acdabf1b68e4473376b41aa4dc50147328a0e319bafd1e248ef973afa +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 67 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { return 'PROXY proxy.test:2' } \ No newline at end of file diff --git a/cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 b/cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 deleted file mode 100644 index 9be23af..0000000 --- a/cache/d8fd1758481fb09deb7d1bffb141b12f8650d40fec098903d29ecb7ca088acb6 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 53 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:59:16 GMT -X-Cached-Time: 2026-03-22T16:59:16Z -X-Request-Time: 2026-03-22T16:59:16Z -X-Response-Time: 2026-03-22T16:59:16Z - -function FindProxyForURL(url, host) { throw 'error' } \ No newline at end of file diff --git a/cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef b/cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef deleted file mode 100644 index a3060c2..0000000 --- a/cache/db67ad418550730ec11bc2ce2448d28c14e76d67bf88177f6f617ab0e71e24ef +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 13 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:14 GMT -X-Cached-Time: 2026-03-22T16:54:14Z -X-Request-Time: 2026-03-22T16:54:14Z -X-Response-Time: 2026-03-22T16:54:14Z - -test script 2 \ No newline at end of file diff --git a/cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 b/cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 deleted file mode 100644 index dbd4159..0000000 --- a/cache/eace0c216ad07ebd003cf3c5d6da8eb2c0f0da23e1b4b915591c4554c4e3cf01 +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 75 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:14 GMT -X-Cached-Time: 2026-03-22T16:54:14Z -X-Request-Time: 2026-03-22T16:54:14Z -X-Response-Time: 2026-03-22T16:54:14Z - -function FindProxyForURL(url, host) { return 'PROXY proxy.test:1; DIRECT' } \ No newline at end of file diff --git a/cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f b/cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f deleted file mode 100644 index 02a0cd5..0000000 --- a/cache/ef486688f3c4495bedcf23129c5efa252f6cd96b6de732f94bd885ef3da2fd0f +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 53 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:14 GMT -X-Cached-Time: 2026-03-22T16:54:14Z -X-Request-Time: 2026-03-22T16:54:14Z -X-Response-Time: 2026-03-22T16:54:14Z - -function FindProxyForURL(url, host) { throw 'error' } \ No newline at end of file diff --git a/cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e b/cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e deleted file mode 100644 index b7349f9..0000000 --- a/cache/efed0a3243f33f5f985c88f83ecf5b581c44cf5a6accd02bcfeb3ea4dcfbd24e +++ /dev/null @@ -1,9 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 65 -Content-Type: text/plain; charset=utf-8 -Date: Sun, 22 Mar 2026 16:54:15 GMT -X-Cached-Time: 2026-03-22T16:54:15Z -X-Request-Time: 2026-03-22T16:54:15Z -X-Response-Time: 2026-03-22T16:54:15Z - -function FindProxyForURL(url, host) { return 'HTTPS https.test' } \ No newline at end of file diff --git a/pacfetcher.go b/pacfetcher.go index d115124..42227e0 100644 --- a/pacfetcher.go +++ b/pacfetcher.go @@ -18,7 +18,6 @@ import ( "time" "github.com/sandrolain/httpcache" - "github.com/sandrolain/httpcache/diskcache" ) const maxResponseBytes = 1 * 1024 * 1024 @@ -53,8 +52,8 @@ func newPACFetcher(pacurl string) *pacFetcher { // Base transport without proxy (important: avoid proxy loop) baseTransport := &http.Transport{Proxy: nil} - // Add HTTP caching - cacheTransport := httpcache.NewTransport(diskcache.New("cache")) + // ✅ Use in-memory cache (FIXED) + cacheTransport := httpcache.NewTransport(httpcache.NewMemoryCache()) cacheTransport.Transport = baseTransport client = &http.Client{ @@ -146,7 +145,6 @@ func (pf *pacFetcher) download() []byte { return pac } - // Cached HTTP request (handled automatically by transport) resp, err := requireOK(pf.client.Get(pacurl)) if err != nil { log.Printf("Error downloading PAC file, will retry after %v: %q", @@ -154,10 +152,9 @@ func (pf *pacFetcher) download() []byte { time.Sleep(delayAfterFailedDownload) - // Retry once if resp, err = requireOK(pf.client.Get(pacurl)); err != nil { log.Printf("Error downloading PAC file, giving up: %q", err) - return nil // ❗ No fallback to cached PAC (correct behavior) + return nil } } defer resp.Body.Close() @@ -178,4 +175,4 @@ func (pf *pacFetcher) download() []byte { func (pf *pacFetcher) isConnected() bool { return pf.connected -} +} \ No newline at end of file diff --git a/pacfetcher_cache_test.go b/pacfetcher_cache_test.go new file mode 100644 index 0000000..e011ef9 --- /dev/null +++ b/pacfetcher_cache_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestPACCacheNoFallback(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("function FindProxyForURL() { return 'DIRECT'; }")) + })) + + pf := newPACFetcher(server.URL) + + data := pf.download() + if data == nil { + t.Fatal("expected PAC data on first fetch") + } + + server.Close() + + data = pf.download() + if data != nil { + t.Fatal("expected nil when server is down (no cache fallback)") + } +} diff --git a/pacfinder_darwin_test.go b/pacfinder_darwin_test.go index 28e9ec2..1781865 100644 --- a/pacfinder_darwin_test.go +++ b/pacfinder_darwin_test.go @@ -1,4 +1,4 @@ -// Copyright 2019, 2021, 2022 The Alpaca Authors +// Copyright 2019, 2021, 2022, 2025 The Alpaca Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From f2b95bbf2708f6b546b89f69ff2721fa8c3bd724 Mon Sep 17 00:00:00 2001 From: Sneha S Biju Date: Wed, 25 Mar 2026 00:47:27 +0000 Subject: [PATCH 3/3] fix: restore license header, use in-memory cache, add test for no cache fallback --- .gitignore | 1 + pacfetcher.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 77762e5..acf34f8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __debug_bin* .idea .DS_Store cache/ +cache/ diff --git a/pacfetcher.go b/pacfetcher.go index 42227e0..88713ca 100644 --- a/pacfetcher.go +++ b/pacfetcher.go @@ -1,8 +1,16 @@ // Copyright 2019, 2021, 2022, 2025 The Alpaca Authors // // Licensed under the Apache License, Version 2.0 (the "License"); -// ... - +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package main import (