|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -59,8 +59,9 @@ class JdkClientHttpRequest extends AbstractClientHttpRequest {
|
59 | 59 | private final HttpRequest.Builder builder;
|
60 | 60 |
|
61 | 61 |
|
62 |
| - public JdkClientHttpRequest(HttpMethod httpMethod, URI uri, DataBufferFactory bufferFactory, |
63 |
| - @Nullable Duration readTimeout) { |
| 62 | + public JdkClientHttpRequest( |
| 63 | + HttpMethod httpMethod, URI uri, DataBufferFactory bufferFactory, @Nullable Duration readTimeout) { |
| 64 | + |
64 | 65 | Assert.notNull(httpMethod, "HttpMethod is required");
|
65 | 66 | Assert.notNull(uri, "URI is required");
|
66 | 67 | Assert.notNull(bufferFactory, "DataBufferFactory is required");
|
@@ -97,32 +98,6 @@ public <T> T getNativeRequest() {
|
97 | 98 | }
|
98 | 99 |
|
99 | 100 |
|
100 |
| - @Override |
101 |
| - protected void applyHeaders() { |
102 |
| - for (Map.Entry<String, List<String>> entry : getHeaders().headerSet()) { |
103 |
| - if (entry.getKey().equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { |
104 |
| - // content-length is specified when writing |
105 |
| - continue; |
106 |
| - } |
107 |
| - for (String value : entry.getValue()) { |
108 |
| - this.builder.header(entry.getKey(), value); |
109 |
| - } |
110 |
| - } |
111 |
| - if (!getHeaders().containsHeader(HttpHeaders.ACCEPT)) { |
112 |
| - this.builder.header(HttpHeaders.ACCEPT, "*/*"); |
113 |
| - } |
114 |
| - } |
115 |
| - |
116 |
| - @Override |
117 |
| - protected void applyCookies() { |
118 |
| - MultiValueMap<String, HttpCookie> cookies = getCookies(); |
119 |
| - if (cookies.isEmpty()) { |
120 |
| - return; |
121 |
| - } |
122 |
| - this.builder.header(HttpHeaders.COOKIE, cookies.values().stream() |
123 |
| - .flatMap(List::stream).map(HttpCookie::toString).collect(Collectors.joining(";"))); |
124 |
| - } |
125 |
| - |
126 | 101 | @Override
|
127 | 102 | public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
|
128 | 103 | return doCommit(() -> {
|
@@ -162,4 +137,30 @@ public Mono<Void> setComplete() {
|
162 | 137 | });
|
163 | 138 | }
|
164 | 139 |
|
| 140 | + @Override |
| 141 | + protected void applyHeaders() { |
| 142 | + for (Map.Entry<String, List<String>> entry : getHeaders().headerSet()) { |
| 143 | + if (entry.getKey().equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) { |
| 144 | + // content-length is specified when writing |
| 145 | + continue; |
| 146 | + } |
| 147 | + for (String value : entry.getValue()) { |
| 148 | + this.builder.header(entry.getKey(), value); |
| 149 | + } |
| 150 | + } |
| 151 | + if (!getHeaders().containsHeader(HttpHeaders.ACCEPT)) { |
| 152 | + this.builder.header(HttpHeaders.ACCEPT, "*/*"); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + protected void applyCookies() { |
| 158 | + MultiValueMap<String, HttpCookie> cookies = getCookies(); |
| 159 | + if (cookies.isEmpty()) { |
| 160 | + return; |
| 161 | + } |
| 162 | + this.builder.header(HttpHeaders.COOKIE, cookies.values().stream() |
| 163 | + .flatMap(List::stream).map(HttpCookie::toString).collect(Collectors.joining(";"))); |
| 164 | + } |
| 165 | + |
165 | 166 | }
|
0 commit comments