Skip to content

Commit

Permalink
Use default ports when comparing hosts
Browse files Browse the repository at this point in the history
Refers to #382
  • Loading branch information
michel-kraemer committed Feb 26, 2024
1 parent e287889 commit 1641eb8
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,25 @@ public RemoveSensitiveHeadersInterceptor(HttpHost originalHost) {
this.originalHost = originalHost;
}

private int portOrDefault(int port, String scheme) {
if (port != -1) {
return port;
}
if ("https".equals(scheme)) {
return 443;
} else if ("http".equals(scheme)) {
return 80;
}
return -1;
}

@Override
public void process(HttpRequest request, EntityDetails entity, HttpContext context) {
int originalPort = portOrDefault(originalHost.getPort(), originalHost.getSchemeName());
int requestPort = portOrDefault(request.getAuthority().getPort(), request.getScheme());
if (request.getAuthority() == null ||
!request.getAuthority().getHostName().equals(originalHost.getHostName()) ||
request.getAuthority().getPort() != originalHost.getPort()) {
requestPort != originalPort) {
request.removeHeaders(HttpHeaders.AUTHORIZATION);
request.removeHeaders(HttpHeaders.COOKIE);
request.removeHeaders("Cookie2");
Expand Down

0 comments on commit 1641eb8

Please sign in to comment.