Skip to content

Commit

Permalink
Rearrange HttpHeaders adapters
Browse files Browse the repository at this point in the history
This commit moves HttpHeaders that are used in multiple places (client
and server, reactive and non-reactive) to a new, separate http.support
package.

Closes gh-30823
  • Loading branch information
poutsma committed Jul 6, 2023
1 parent 8e9528d commit 3d2befc
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 880 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import java.io.InputStream;

import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.support.HttpComponentsHeadersAdapter;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;

/**
* {@link ClientHttpResponse} implementation based on
Expand Down Expand Up @@ -65,10 +66,8 @@ public String getStatusText() {
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
for (Header header : this.httpResponse.getHeaders()) {
this.headers.add(header.getName(), header.getValue());
}
MultiValueMap<String, String> adapter = new HttpComponentsHeadersAdapter(this.httpResponse);
this.headers = HttpHeaders.readOnlyHttpHeaders(adapter);
}
return this.headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

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

/**
* {@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 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.HttpComponentsHeadersAdapter;
import org.springframework.lang.Nullable;

/**
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.HttpComponentsHeadersAdapter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

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.JettyHeadersAdapter;

/**
* {@link ClientHttpRequest} implementation for the Jetty ReactiveStreams HTTP client.
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.JettyHeadersAdapter;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ZeroCopyHttpOutputMessage;
import org.springframework.http.support.Netty4HeadersAdapter;

/**
* {@link ClientHttpRequest} implementation for the Reactor-Netty HTTP client.
Expand Down Expand Up @@ -136,7 +137,7 @@ protected void applyCookies() {

@Override
protected HttpHeaders initReadOnlyHeaders() {
return HttpHeaders.readOnlyHttpHeaders(new NettyHeadersAdapter(this.request.requestHeaders()));
return HttpHeaders.readOnlyHttpHeaders(new Netty4HeadersAdapter(this.request.requestHeaders()));
}

}
Loading

0 comments on commit 3d2befc

Please sign in to comment.