Skip to content

Commit

Permalink
Remove auth preserving request
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Nov 6, 2024
1 parent b3496f3 commit 25fe2f3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 117 deletions.
29 changes: 5 additions & 24 deletions http-client/src/main/java/io/airlift/http/client/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public final class Request
private final Optional<DataSize> maxContentLength;
private final Optional<SpanBuilder> spanBuilder;
private final boolean followRedirects;
private final boolean preserveAuthorizationOnRedirect;

private Request(
Optional<HttpVersion> httpVersion,
Expand All @@ -60,8 +59,7 @@ private Request(
BodyGenerator bodyGenerator,
Optional<DataSize> maxContentLength,
Optional<SpanBuilder> spanBuilder,
boolean followRedirects,
boolean preserveAuthorizationOnRedirect)
boolean followRedirects)
{
requireNonNull(uri, "uri is null");
checkArgument(uri.getHost() != null, "uri does not have a host: %s", uri);
Expand All @@ -80,7 +78,6 @@ private Request(
this.maxContentLength = requireNonNull(maxContentLength, "maxContentLength is null");
this.spanBuilder = requireNonNull(spanBuilder, "spanBuilder is null");
this.followRedirects = followRedirects;
this.preserveAuthorizationOnRedirect = preserveAuthorizationOnRedirect;
}

public static Request.Builder builder()
Expand Down Expand Up @@ -147,11 +144,6 @@ public boolean isFollowRedirects()
return followRedirects;
}

public boolean isPreserveAuthorizationOnRedirect()
{
return preserveAuthorizationOnRedirect;
}

@Override
public String toString()
{
Expand All @@ -166,7 +158,6 @@ public String toString()
.add("bodyGenerator", bodyGenerator)
.add("spanBuilder", spanBuilder.isPresent() ? "present" : "empty")
.add("followRedirects", followRedirects)
.add("preserveAuthorizationOnRedirect", preserveAuthorizationOnRedirect)
.toString();
}

Expand All @@ -186,8 +177,7 @@ public boolean equals(Object o)
Objects.equals(maxContentLength, r.maxContentLength) &&
Objects.equals(bodyGenerator, r.bodyGenerator) &&
Objects.equals(spanBuilder, r.spanBuilder) &&
Objects.equals(followRedirects, r.followRedirects) &&
Objects.equals(preserveAuthorizationOnRedirect, r.preserveAuthorizationOnRedirect);
Objects.equals(followRedirects, r.followRedirects);
}

@Override
Expand All @@ -203,8 +193,7 @@ public int hashCode()
maxContentLength,
bodyGenerator,
spanBuilder,
followRedirects,
preserveAuthorizationOnRedirect);
followRedirects);
}

public static final class Builder
Expand Down Expand Up @@ -248,8 +237,7 @@ public static Builder fromRequest(Request request)
.setBodyGenerator(request.getBodyGenerator())
.setSpanBuilder(request.getSpanBuilder().orElse(null))
.setFollowRedirects(request.isFollowRedirects())
.setVersion(request.getHttpVersion().orElse(null))
.setPreserveAuthorizationOnRedirect(request.isPreserveAuthorizationOnRedirect());
.setVersion(request.getHttpVersion().orElse(null));

request.getRequestTimeout().ifPresent(builder::setRequestTimeout);
request.getIdleTimeout().ifPresent(builder::setIdleTimeout);
Expand Down Expand Up @@ -343,12 +331,6 @@ public Builder setMaxContentLength(DataSize maxContentLength)
return this;
}

public Builder setPreserveAuthorizationOnRedirect(boolean preserveAuthorizationOnRedirect)
{
this.preserveAuthorizationOnRedirect = preserveAuthorizationOnRedirect;
return this;
}

public Request build()
{
return new Request(
Expand All @@ -361,8 +343,7 @@ public Request build()
bodyGenerator,
maxContentLength,
Optional.ofNullable(spanBuilder),
followRedirects,
preserveAuthorizationOnRedirect);
followRedirects);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.net.InetAddresses.isInetAddress;
import static io.airlift.http.client.ResponseHandlerUtils.propagate;
import static io.airlift.http.client.jetty.AuthorizationPreservingHttpClient.setPreserveAuthorization;
import static io.airlift.node.AddressToHostname.tryDecodeHostnameToAddress;
import static io.airlift.security.cert.CertificateBuilder.certificateBuilder;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
Expand Down Expand Up @@ -279,7 +278,7 @@ protected void configure(SelectableChannel selectable)
connector.setSelectors(config.getSelectorCount());
connector.setSslContextFactory(sslContextFactory);

httpClient = new AuthorizationPreservingHttpClient(getClientTransport(connector, config));
httpClient = new HttpClient(getClientTransport(connector, config));

// request and response buffer size
httpClient.setRequestBufferSize(toIntExact(config.getRequestBufferSize().toBytes()));
Expand Down Expand Up @@ -990,8 +989,6 @@ private RequestContext buildRequestContext(Request finalRequest)

jettyRequest.followRedirects(finalRequest.isFollowRedirects());

setPreserveAuthorization(jettyRequest, finalRequest.isPreserveAuthorizationOnRedirect());

// timeouts
jettyRequest.timeout(finalRequest.getRequestTimeout().orElse(requestTimeout).toMillis(), MILLISECONDS);
jettyRequest.idleTimeout(finalRequest.getIdleTimeout().orElse(idleTimeout).toMillis(), MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,43 +651,6 @@ public void testRequestHeaders()
}
}

@Test
public void testRedirectRequestHeaders()
throws Exception
{
String basic = "Basic dGVzdDphYmM=";
String bearer = "Bearer testxyz";

try (CloseableTestHttpServer server = newServer()) {
Request request = prepareGet()
.setUri(URI.create(server.baseURI().toASCIIString() + "/?redirect=/redirect"))
.addHeader("X-Test", "xtest1")
.addHeader("X-Test", "xtest2")
.setHeader(USER_AGENT, "testagent")
.addHeader(AUTHORIZATION, basic)
.addHeader(AUTHORIZATION, bearer)
.build();

StatusResponse response = executeRequest(server, request, createStatusResponseHandler());
assertThat(response.getStatusCode()).isEqualTo(200);
assertThat(server.servlet().getRequestUri()).isEqualTo(URI.create(server.baseURI().toASCIIString() + "/redirect"));
assertThat(server.servlet().getRequestHeaders("X-Test")).containsExactly("xtest1", "xtest2");
assertThat(server.servlet().getRequestHeaders(USER_AGENT)).containsExactly("testagent");
assertThat(server.servlet().getRequestHeaders(AUTHORIZATION)).isEmpty();

request = Request.Builder.fromRequest(request)
.setPreserveAuthorizationOnRedirect(true)
.build();

response = executeRequest(server, request, createStatusResponseHandler());
assertThat(response.getStatusCode()).isEqualTo(200);
assertThat(server.servlet().getRequestUri()).isEqualTo(URI.create(server.baseURI().toASCIIString() + "/redirect"));
assertThat(server.servlet().getRequestHeaders("X-Test")).containsExactly("xtest1", "xtest2");
assertThat(server.servlet().getRequestHeaders(USER_AGENT)).containsExactly("testagent");
assertThat(server.servlet().getRequestHeaders(AUTHORIZATION)).containsExactly(basic, bearer);
}
}

@Test
public void testFollowRedirects()
throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ public void testEquivalence()
.addEquivalentGroup(
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).build(),
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).build(),
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).setFollowRedirects(true).build(),
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).setPreserveAuthorizationOnRedirect(false).build())
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).setFollowRedirects(true).build())
.addEquivalentGroup(
preparePut().setUri(createUriA()).addHeaders(createHeadersA()).setFollowRedirects(false).build())
.addEquivalentGroup(
preparePut().setUri(createUriA()).addHeaders(createHeadersA()).setPreserveAuthorizationOnRedirect(true).build())
.addEquivalentGroup(
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).setBodyGenerator(bodyGenerator).build(),
prepareGet().setUri(createUriA()).addHeaders(createHeadersA()).setBodyGenerator(bodyGenerator).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private static Request createRequest()
.addHeader("anotherheader", "anothervalue")
.setBodyGenerator(NULL_BODY_GENERATOR)
.setFollowRedirects(false)
.setPreserveAuthorizationOnRedirect(true)
.build();
}
}

0 comments on commit 25fe2f3

Please sign in to comment.