我有一个 Java 应用程序需要 ping 第三方网站。为了更安全,我使用 Squid 作为代理:
+-----------+ +-------------+ +--------------------+
| Java App. |---->| Squid Proxy |---->| Third party server |
+-----------+ +-------------+ +--------------------+
系统似乎按预期运行,但当我查看 Squid 代理日志时,我看到大量 407 错误。这是正常的吗?比例似乎接近 50/50(200 比 407 多一点)。我想知道 Java 代理代码是否并不总是发送凭据,这可以解释这么多 407 错误。
Java 代码使用RequestBuilder
如下:
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.Realm;
import org.asynchttpclient.Request;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.proxy.ProxyServer;
import org.asynchttpclient.proxy.ProxyType;
[...]
private final AsyncHttpClient asyncHttpClient;
[...]
var reqBuilder = new RequestBuilder(GET);
reqBuilder.setUrl(url);
var realm = new Realm.Builder(proxyUser, proxySecret)
.setScheme(Realm.AuthScheme.BASIC);
var proxy = new ProxyServer.Builder(proxyHost, proxyPort)
.setSecuredPort(proxyPort)
.setProxyType(ProxyType.HTTP)
.setRealm(realm));
reqBuilder.setProxyServer(proxy);
Request request = reqBuilder.build();
return asyncHttpClient
.executeRequest(request)
.toCompletableFuture()
.handle(
(r, t) -> {
return (Response) Response.ok();
});
_ 注意:我删除了错误处理以使代码看起来简单明了。_
最后,Squid 配置包含以下有关基本身份验证的行:
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/squid.htpasswd
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
您觉得我的设置有什么问题吗?