Skip to content

Commit

Permalink
Refactor HttpHeaders adapters
Browse files Browse the repository at this point in the history
This commit moves all HttpHeaders to a new http.support package, hiding
them behind static methods in HeadersAdapterUtils, so that they can
be used from client and server, reactive and non-reactive.
  • Loading branch information
poutsma committed Jul 5, 2023
1 parent bcf4812 commit 6aef821
Show file tree
Hide file tree
Showing 28 changed files with 149 additions and 907 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.util.MultiValueMap;
import org.springframework.http.support.HeadersAdapterUtils;

/**
* {@link ClientHttpResponse} implementation based on based on Jetty's
* {@link ClientHttpResponse} implementation based on Jetty's
* {@link org.eclipse.jetty.client.HttpClient}.
*
* @author Arjen Poutsma
Expand All @@ -45,8 +45,7 @@ public JettyClientHttpResponse(Response response, InputStream inputStream) {
this.response = response;
this.body = inputStream;

MultiValueMap<String, String> headers = new JettyHeadersAdapter(response.getHeaders());
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
this.headers = HttpHeaders.readOnlyHttpHeaders(HeadersAdapterUtils.jetty(response.getHeaders()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.support.HeadersAdapterUtils;
import org.springframework.lang.Nullable;

/**
Expand Down Expand Up @@ -158,7 +159,7 @@ protected void applyCookies() {

@Override
protected HttpHeaders initReadOnlyHeaders() {
return HttpHeaders.readOnlyHttpHeaders(new HttpComponentsHeadersAdapter(this.httpRequest));
return HttpHeaders.readOnlyHttpHeaders(HeadersAdapterUtils.httpComponents(this.httpRequest));
}

public AsyncRequestProducer toRequestProducer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseCookie;
import org.springframework.http.support.HeadersAdapterUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

Expand Down Expand Up @@ -62,8 +63,7 @@ public HttpComponentsClientHttpResponse(DataBufferFactory dataBufferFactory,
this.message = message;
this.context = context;

MultiValueMap<String, String> adapter = new HttpComponentsHeadersAdapter(message.getHead());
this.headers = HttpHeaders.readOnlyHttpHeaders(adapter);
this.headers = HttpHeaders.readOnlyHttpHeaders(HeadersAdapterUtils.httpComponents(message.getHead()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.JettyHeadersAdapter;
import org.springframework.http.support.HeadersAdapterUtils;

/**
* {@link ClientHttpRequest} implementation for the Jetty ReactiveStreams HTTP client.
Expand Down Expand Up @@ -147,7 +147,7 @@ protected void applyHeaders() {

@Override
protected HttpHeaders initReadOnlyHeaders() {
return HttpHeaders.readOnlyHttpHeaders(new JettyHeadersAdapter(this.jettyRequest.getHeaders()));
return HttpHeaders.readOnlyHttpHeaders(HeadersAdapterUtils.jetty(this.jettyRequest.getHeaders()));
}

public ReactiveRequest toReactiveRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseCookie;
import org.springframework.http.client.JettyHeadersAdapter;
import org.springframework.http.support.HeadersAdapterUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
Expand Down Expand Up @@ -59,8 +59,7 @@ public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<Data
this.reactiveResponse = reactiveResponse;
this.content = Flux.from(content);

MultiValueMap<String, String> headers = new JettyHeadersAdapter(reactiveResponse.getHeaders());
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
this.headers = HttpHeaders.readOnlyHttpHeaders(HeadersAdapterUtils.jetty(reactiveResponse.getHeaders()));
}


Expand Down

This file was deleted.

0 comments on commit 6aef821

Please sign in to comment.