Skip to content

Commit b2d9292

Browse files
committed
review:fix: headers are case-insensitive
Signed-off-by: Marc Nuri <[email protected]>
1 parent b120d18 commit b2d9292

File tree

5 files changed

+68
-46
lines changed

5 files changed

+68
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Fix #6906: Knative VolatileTime should be serialized as String
88
* Fix #6930: Add support for Boolean enums in the java-generator
99
* Fix #6886: Remove invalid JUnit 4 references
10-
* Fix #6917: Fabric 8 client does not authenticate correctly on openshift if the returned Location header is lower case
10+
* Fix #6917: Client does not authenticate correctly on OpenShift if the returned Location header is lower-case
1111

1212
#### Improvements
1313
* Fix #6863: ensuring SerialExecutor does not throw RejectedExecutionException to prevent unnecessary error logs

httpclient-vertx/src/main/java/io/fabric8/kubernetes/client/vertx/VertxHttpRequest.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.fabric8.kubernetes.client.vertx;
1717

1818
import io.fabric8.kubernetes.client.http.AsyncBody;
19-
import io.fabric8.kubernetes.client.http.HttpRequest;
2019
import io.fabric8.kubernetes.client.http.HttpResponse;
2120
import io.fabric8.kubernetes.client.http.StandardHttpRequest;
2221
import io.fabric8.kubernetes.client.http.StandardHttpRequest.BodyContent;
@@ -34,54 +33,11 @@
3433
import java.util.LinkedHashMap;
3534
import java.util.List;
3635
import java.util.Map;
37-
import java.util.Optional;
3836
import java.util.concurrent.CompletableFuture;
3937
import java.util.function.Function;
4038

4139
class VertxHttpRequest {
4240

43-
private static final class VertxHttpResponse implements HttpResponse<AsyncBody> {
44-
private final AsyncBody result;
45-
private final HttpClientResponse resp;
46-
private final HttpRequest request;
47-
48-
private VertxHttpResponse(AsyncBody result, HttpClientResponse resp, HttpRequest request) {
49-
this.result = result;
50-
this.resp = resp;
51-
this.request = request;
52-
}
53-
54-
@Override
55-
public int code() {
56-
return resp.statusCode();
57-
}
58-
59-
@Override
60-
public AsyncBody body() {
61-
return result;
62-
}
63-
64-
@Override
65-
public HttpRequest request() {
66-
return request;
67-
}
68-
69-
@Override
70-
public Optional<HttpResponse<?>> previousResponse() {
71-
return Optional.empty();
72-
}
73-
74-
@Override
75-
public List<String> headers(String key) {
76-
return resp.headers().getAll(key);
77-
}
78-
79-
@Override
80-
public Map<String, List<String>> headers() {
81-
return toHeadersMap(resp.headers());
82-
}
83-
}
84-
8541
final Vertx vertx;
8642
private final RequestOptions options;
8743
private final StandardHttpRequest request;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.kubernetes.client.vertx;
17+
18+
import io.fabric8.kubernetes.client.http.AsyncBody;
19+
import io.fabric8.kubernetes.client.http.HttpRequest;
20+
import io.fabric8.kubernetes.client.http.HttpResponse;
21+
import io.fabric8.kubernetes.client.http.StandardHttpHeaders;
22+
import io.vertx.core.http.HttpClientResponse;
23+
24+
import java.util.Optional;
25+
26+
public class VertxHttpResponse extends StandardHttpHeaders implements HttpResponse<AsyncBody> {
27+
private final AsyncBody result;
28+
private final HttpClientResponse resp;
29+
private final HttpRequest request;
30+
31+
VertxHttpResponse(AsyncBody result, HttpClientResponse resp, HttpRequest request) {
32+
super(VertxHttpRequest.toHeadersMap(resp.headers()));
33+
this.result = result;
34+
this.resp = resp;
35+
this.request = request;
36+
}
37+
38+
@Override
39+
public int code() {
40+
return resp.statusCode();
41+
}
42+
43+
@Override
44+
public AsyncBody body() {
45+
return result;
46+
}
47+
48+
@Override
49+
public HttpRequest request() {
50+
return request;
51+
}
52+
53+
@Override
54+
public Optional<HttpResponse<?>> previousResponse() {
55+
return Optional.empty();
56+
}
57+
58+
}

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/http/HttpHeaders.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ public interface HttpHeaders {
2323

2424
/**
2525
* Returns a List of all the Header String values for the provided key/name.
26+
* <p>
27+
* key is case-insensitive as defined in RFC 2616.
2628
*
2729
* @param key The header key/name for which to provide the values.
2830
* @return the List of header values for the provided key.
31+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-4.2">RFC 2616 Section 4.2</a>
2932
*/
3033
List<String> headers(String key);
3134

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/http/StandardHttpHeaders.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public StandardHttpHeaders(Map<String, List<String>> headers) {
4141

4242
@Override
4343
public List<String> headers(String key) {
44-
return Collections.unmodifiableList(headers.getOrDefault(key, Collections.emptyList()));
44+
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
45+
if (entry.getKey().equalsIgnoreCase(key)) {
46+
return Collections.unmodifiableList(entry.getValue());
47+
}
48+
}
49+
return Collections.emptyList();
4550
}
4651

4752
@Override

0 commit comments

Comments
 (0)