MCPcopy Index your code
hub / github.com/OpenFeign/feign / Http2Client

Class Http2Client

java11/src/main/java/feign/http2client/Http2Client.java:60–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58import java.util.zip.InflaterInputStream;
59
60public class Http2Client implements Client, AsyncClient<Object> {
61
62 private final HttpClient client;
63
64 private final Map<Integer, SoftReference<HttpClient>> clients = new ConcurrentHashMap<>();
65
66 /**
67 * Creates the new Http2Client using following defaults:
68 *
69 * <ul>
70 * <li>Connect Timeout: 10 seconds, as {@link Request.Options#Options()} uses
71 * <li>Follow all 3xx redirects
72 * <li>HTTP 2
73 * </ul>
74 *
75 * @see Request.Options#Options()
76 */
77 public Http2Client() {
78 this(
79 HttpClient.newBuilder()
80 .followRedirects(Redirect.ALWAYS)
81 .version(Version.HTTP_2)
82 .connectTimeout(Duration.ofMillis(10000))
83 .build());
84 }
85
86 public Http2Client(Options options) {
87 this(newClientBuilder(options).version(Version.HTTP_2).build());
88 }
89
90 public Http2Client(HttpClient client) {
91 this.client = Util.checkNotNull(client, "HttpClient must not be null");
92 }
93
94 @Override
95 public Response execute(Request request, Options options) throws IOException {
96 final HttpRequest httpRequest;
97 try {
98 httpRequest = newRequestBuilder(request, options).version(client.version()).build();
99 } catch (URISyntaxException e) {
100 throw new IOException("Invalid uri " + request.url(), e);
101 }
102
103 HttpClient clientForRequest = getOrCreateClient(options);
104 HttpResponse<InputStream> httpResponse;
105 try {
106 httpResponse = clientForRequest.send(httpRequest, BodyHandlers.ofInputStream());
107 } catch (final InterruptedException e) {
108 Thread.currentThread().interrupt();
109 throw new IOException(e);
110 }
111
112 return toFeignResponse(request, httpResponse);
113 }
114
115 @Override
116 public CompletableFuture<Response> execute(
117 Request request, Options options, Optional<Object> requestContext) {

Callers

nothing calls this directly

Calls 1

ofMethod · 0.45

Tested by

no test coverage detected