1
0
mirror of synced 2025-07-29 11:01:13 +03:00

Proxy problems (#2165)

* Fix proxy problems

* Auto redirect problem (http → https → https)
This commit is contained in:
yhirose
2025-06-28 00:14:01 -04:00
committed by GitHub
parent 696c02f2bc
commit e1ab5a604b
6 changed files with 180 additions and 29 deletions

View File

@ -1,9 +1,9 @@
FROM centos:7
FROM alpine:latest
ARG auth="basic"
ARG port="3128"
RUN yum install -y squid
RUN apk update && apk add --no-cache squid
COPY ./${auth}_squid.conf /etc/squid/squid.conf
COPY ./${auth}_passwd /etc/squid/passwd

View File

@ -27,7 +27,7 @@ acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

View File

@ -27,7 +27,7 @@ acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
auth_param digest program /usr/lib64/squid/digest_file_auth /etc/squid/passwd
auth_param digest program /usr/lib/squid/digest_file_auth /etc/squid/passwd
auth_param digest realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

View File

@ -1,5 +1,3 @@
version: '2'
services:
squid_basic:
image: squid_basic

View File

@ -1,3 +1,4 @@
#include <chrono>
#include <future>
#include <gtest/gtest.h>
#include <httplib.h>
@ -5,6 +6,14 @@
using namespace std;
using namespace httplib;
std::string normalizeJson(const std::string &json) {
std::string result;
for (char c : json) {
if (c != ' ' && c != '\t' && c != '\n' && c != '\r') { result += c; }
}
return result;
}
template <typename T> void ProxyTest(T &cli, bool basic) {
cli.set_proxy("localhost", basic ? 3128 : 3129);
auto res = cli.Get("/httpbin/get");
@ -81,7 +90,7 @@ TEST(RedirectTest, YouTubeNoSSLBasic) {
RedirectProxyText(cli, "/", true);
}
TEST(RedirectTest, DISABLED_YouTubeNoSSLDigest) {
TEST(RedirectTest, YouTubeNoSSLDigest) {
Client cli("youtube.com");
RedirectProxyText(cli, "/", false);
}
@ -92,6 +101,7 @@ TEST(RedirectTest, YouTubeSSLBasic) {
}
TEST(RedirectTest, YouTubeSSLDigest) {
std::this_thread::sleep_for(std::chrono::seconds(3));
SSLClient cli("youtube.com");
RedirectProxyText(cli, "/", false);
}
@ -113,8 +123,8 @@ template <typename T> void BaseAuthTestFromHTTPWatch(T &cli) {
auto res = cli.Get("/basic-auth/hello/world",
{make_basic_authentication_header("hello", "world")});
ASSERT_TRUE(res != nullptr);
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
res->body);
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
normalizeJson(res->body));
EXPECT_EQ(StatusCode::OK_200, res->status);
}
@ -122,8 +132,8 @@ template <typename T> void BaseAuthTestFromHTTPWatch(T &cli) {
cli.set_basic_auth("hello", "world");
auto res = cli.Get("/basic-auth/hello/world");
ASSERT_TRUE(res != nullptr);
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
res->body);
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
normalizeJson(res->body));
EXPECT_EQ(StatusCode::OK_200, res->status);
}
@ -179,8 +189,8 @@ template <typename T> void DigestAuthTestFromHTTPWatch(T &cli) {
for (auto path : paths) {
auto res = cli.Get(path.c_str());
ASSERT_TRUE(res != nullptr);
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
res->body);
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
normalizeJson(res->body));
EXPECT_EQ(StatusCode::OK_200, res->status);
}
@ -249,8 +259,8 @@ template <typename T> void KeepAliveTest(T &cli, bool basic) {
for (auto path : paths) {
auto res = cli.Get(path.c_str());
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
res->body);
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
normalizeJson(res->body));
EXPECT_EQ(StatusCode::OK_200, res->status);
}
}