Skip to content

Commit

Permalink
4.x: Replace deprecated method Header.value() on Header.get()
Browse files Browse the repository at this point in the history
  • Loading branch information
Captain1653 committed Jun 11, 2024
1 parent 335c98b commit 6a8700d
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -217,7 +217,7 @@ protected boolean matchesSafely(Headers httpHeaders) {
if (httpHeaders.contains(name)) {
Header headerValue = httpHeaders.get(name);
if (headerValue.allValues().size() == 1) {
return valuesMatcher.matches(headerValue.value());
return valuesMatcher.matches(headerValue.get());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void testNotAuthorized(String uri) {
try (Http1ClientResponse response = client.get().uri(uri).request()) {

assertThat(response.status(), is(Status.UNAUTHORIZED_401));
String header = response.headers().get(HeaderNames.WWW_AUTHENTICATE).value();
String header = response.headers().get(HeaderNames.WWW_AUTHENTICATE).get();

assertThat(header.toLowerCase(), containsString("basic"));
assertThat(header, containsString("helidon"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void main(String[] args) {

Headers headers = response.headers();
for (Header header : headers) {
System.out.println("Header: " + header.name() + "=" + header.value());
System.out.println("Header: " + header.name() + "=" + header.get());
}
System.out.println("Entity:");
System.out.println(response.as(String.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -120,7 +120,7 @@ public ContentEncoder encoder(Headers headers) {
return ContentEncoder.NO_OP;
}

String acceptEncoding = headers.get(HeaderNames.ACCEPT_ENCODING).value();
String acceptEncoding = headers.get(HeaderNames.ACCEPT_ENCODING).get();
/*
Accept-Encoding: gzip
Accept-Encoding: gzip, compress, br
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,7 +56,7 @@ public Header get(HeaderName name) {
public Optional<HttpMediaType> contentType() {
if (parserMode == ParserMode.RELAXED) {
return contains(HeaderNameEnum.CONTENT_TYPE)
? Optional.of(HttpMediaType.create(get(HeaderNameEnum.CONTENT_TYPE).value(), parserMode))
? Optional.of(HttpMediaType.create(get(HeaderNameEnum.CONTENT_TYPE).get(), parserMode))
: Optional.empty();
}
return headers.contentType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static ServerRequestHeaders create() {
default Optional<ZonedDateTime> ifModifiedSince() {
if (contains(HeaderNames.IF_MODIFIED_SINCE)) {
return Optional.of(get(HeaderNames.IF_MODIFIED_SINCE))
.map(Header::value)
.map(Header::get)
.map(DateTime::parse);
}

Expand All @@ -95,7 +95,7 @@ default Optional<ZonedDateTime> ifModifiedSince() {
default Optional<ZonedDateTime> ifUnmodifiedSince() {
if (contains(HeaderNames.IF_UNMODIFIED_SINCE)) {
return Optional.of(get(HeaderNames.IF_UNMODIFIED_SINCE))
.map(Header::value)
.map(Header::get)
.map(DateTime::parse);
}
return Optional.empty();
Expand Down Expand Up @@ -189,7 +189,7 @@ default Parameters cookies() {
default Optional<ZonedDateTime> acceptDatetime() {
if (contains(HeaderNames.ACCEPT_DATETIME)) {
return Optional.of(get(HeaderNames.ACCEPT_DATETIME))
.map(Header::value)
.map(Header::get)
.map(DateTime::parse);
}
return Optional.empty();
Expand All @@ -203,7 +203,7 @@ default Optional<ZonedDateTime> acceptDatetime() {
default Optional<ZonedDateTime> date() {
if (contains(HeaderNames.DATE)) {
return Optional.of(get(HeaderNames.DATE))
.map(Header::value)
.map(Header::get)
.map(DateTime::parse);
}
return Optional.empty();
Expand All @@ -221,7 +221,7 @@ default Optional<ZonedDateTime> date() {
default Optional<URI> referer() {
if (contains(HeaderNames.REFERER)) {
return Optional.of(get(HeaderNames.REFERER))
.map(Header::value)
.map(Header::get)
.map(URI::create);
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<HttpMediaType> acceptedTypes() {
List<HttpMediaType> acceptedTypes;

List<String> acceptValues = all(HeaderNames.ACCEPT, List::of);
if (acceptValues.size() == 1 && HUC_ACCEPT_DEFAULT.value().equals(acceptValues.get(0))) {
if (acceptValues.size() == 1 && HUC_ACCEPT_DEFAULT.get().equals(acceptValues.get(0))) {
acceptedTypes = HUC_ACCEPT_DEFAULT_TYPES;
} else {
acceptedTypes = new ArrayList<>(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -224,7 +224,7 @@ void testQuotes() {
.filename("file.txt")
.size(300)
.build();
assertThat(cd.value(), is(equalTo(template)));
assertThat(cd.get(), is(equalTo(template)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public void write(DynamicTable table, Http2HuffmanEncoder huffman, BufferData gr
}

for (Header header : headers) {
String value = header.value();
String value = header.get();
boolean shouldIndex = !header.changing();
boolean neverIndex = header.sensitive();

Expand Down Expand Up @@ -649,7 +649,7 @@ private static Http2Headers createFromWritable(WritableHeaders<?> headers) {

headers.remove(HeaderNames.HOST, it -> {
if (!pseudoHeaders.hasAuthority()) {
pseudoHeaders.authority(it.value());
pseudoHeaders.authority(it.get());
}
});

Expand Down Expand Up @@ -689,7 +689,7 @@ the stream (see Section 5.3). Add one to the value to obtain a
private static void removeFromHeadersAddToPseudo(WritableHeaders<?> headers,
Consumer<String> valueConsumer,
HeaderName pseudoHeader) {
headers.remove(pseudoHeader, it -> valueConsumer.accept(it.value()));
headers.remove(pseudoHeader, it -> valueConsumer.accept(it.get()));
}

private void writeHeader(Http2HuffmanEncoder huffman, DynamicTable table,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +46,7 @@ void testC_2_1() {
DynamicTable dynamicTable = DynamicTable.create(Http2Settings.create());
Headers requestHeaders = headers(hexEncoded, dynamicTable).httpHeaders();

assertThat(requestHeaders.get(HeaderNames.create("custom-key")).value(), is("custom-header"));
assertThat(requestHeaders.get(HeaderNames.create("custom-key")).get(), is("custom-header"));
}

BufferData data(String hexEncoded) {
Expand Down Expand Up @@ -76,7 +76,7 @@ void testC_2_3() {
DynamicTable dynamicTable = DynamicTable.create(Http2Settings.create());
Headers requestHeaders = headers(hexEncoded, dynamicTable).httpHeaders();

assertThat(requestHeaders.get(HeaderNames.create("password")).value(), is("secret"));
assertThat(requestHeaders.get(HeaderNames.create("password")).get(), is("secret"));
assertThat("Dynamic table should be empty", dynamicTable.currentTableSize(), is(0));
}

Expand Down Expand Up @@ -124,7 +124,7 @@ void testC_3() {
assertThat(http2Headers.scheme(), is("http"));
assertThat(http2Headers.path(), is("/"));
assertThat(http2Headers.authority(), is("www.example.com"));
assertThat(requestHeaders.get(HeaderNames.create("cache-control")).value(), is("no-cache"));
assertThat(requestHeaders.get(HeaderNames.create("cache-control")).get(), is("no-cache"));

assertThat("Dynamic table should not be empty", dynamicTable.currentTableSize(), not(0));

Expand All @@ -145,7 +145,7 @@ void testC_3() {
assertThat(http2Headers.scheme(), is("https"));
assertThat(http2Headers.path(), is("/index.html"));
assertThat(http2Headers.authority(), is("www.example.com"));
assertThat(requestHeaders.get(CUSTOM_HEADER_NAME).value(), is("custom-value"));
assertThat(requestHeaders.get(CUSTOM_HEADER_NAME).get(), is("custom-value"));

assertThat("Dynamic table should not be empty", dynamicTable.currentTableSize(), not(0));

Expand Down Expand Up @@ -214,7 +214,7 @@ void testC_4() {
assertThat(http2Headers.scheme(), is("http"));
assertThat(http2Headers.path(), is("/"));
assertThat(http2Headers.authority(), is("www.example.com"));
assertThat(requestHeaders.get(HeaderNames.create("cache-control")).value(), is("no-cache"));
assertThat(requestHeaders.get(HeaderNames.create("cache-control")).get(), is("no-cache"));

assertThat("Dynamic table should not be empty", dynamicTable.currentTableSize(), not(0));

Expand All @@ -235,7 +235,7 @@ void testC_4() {
assertThat(http2Headers.scheme(), is("https"));
assertThat(http2Headers.path(), is("/index.html"));
assertThat(http2Headers.authority(), is("www.example.com"));
assertThat(requestHeaders.get(CUSTOM_HEADER_NAME).value(), is("custom-value"));
assertThat(requestHeaders.get(CUSTOM_HEADER_NAME).get(), is("custom-value"));

assertThat("Dynamic table should not be empty", dynamicTable.currentTableSize(), not(0));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,7 +80,7 @@ public boolean hasEntity() {

private void contentDisposition() {
if (headers.contains(HeaderNames.CONTENT_DISPOSITION)) {
this.contentDisposition = ContentDisposition.parse(headers.get(HeaderNames.CONTENT_DISPOSITION).value());
this.contentDisposition = ContentDisposition.parse(headers.get(HeaderNames.CONTENT_DISPOSITION).get());
} else {
this.contentDisposition = ContentDisposition.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -158,7 +158,7 @@ private JsonObjectBuilder common(ServerRequest req) {
ServerRequestHeaders headers = req.headers();
if (headers.size() > 0) {
JsonObjectBuilder headersBuilder = JSON.createObjectBuilder();
headers.forEach(header -> headersBuilder.add(header.name(), header.value()));
headers.forEach(header -> headersBuilder.add(header.name(), header.get()));
objectBuilder.add("headers", headersBuilder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private static InputStream inputStream(HttpClientConfig clientConfig,
ContentDecoder decoder;

if (encodingSupport.contentDecodingEnabled() && responseHeaders.contains(HeaderNames.CONTENT_ENCODING)) {
String contentEncoding = responseHeaders.get(HeaderNames.CONTENT_ENCODING).value();
String contentEncoding = responseHeaders.get(HeaderNames.CONTENT_ENCODING).get();
if (encodingSupport.contentDecodingSupported(contentEncoding)) {
decoder = encodingSupport.decoder(contentEncoding);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -130,7 +130,7 @@ WebClientServiceResponse doProceed(ClientConnection connection,
if (originalRequest().followRedirects()
&& RedirectionProcessor.redirectionStatusCode(responseStatus)) {
checkRedirectHeaders(responseHeaders);
URI newUri = URI.create(responseHeaders.get(HeaderNames.LOCATION).value());
URI newUri = URI.create(responseHeaders.get(HeaderNames.LOCATION).get());
ClientUri redirectUri = ClientUri.create(newUri);
if (newUri.getHost() == null) {
UriInfo resolvedUri = cos.lastRequest.resolvedUri();
Expand Down Expand Up @@ -440,7 +440,7 @@ private void sendPrologueAndHeader() {
}

private void redirect(Status lastStatus, WritableHeaders<?> headerValues) {
String redirectedUri = headerValues.get(HeaderNames.LOCATION).value();
String redirectedUri = headerValues.get(HeaderNames.LOCATION).get();
ClientUri lastUri = originalRequest.uri();
Method method;
boolean sendEntity;
Expand Down Expand Up @@ -492,7 +492,7 @@ private void redirect(Status lastStatus, WritableHeaders<?> headerValues) {
method = Method.GET;
sendEntity = false;
}
redirectedUri = response.headers().get(HeaderNames.LOCATION).value();
redirectedUri = response.headers().get(HeaderNames.LOCATION).get();
}
} else {
if (!sendEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static Http1ClientResponseImpl invokeWithFollowRedirects(Http1ClientRequestImpl
+ " header present in the response! "
+ "It is not clear where to redirect.");
}
String redirectedUri = clientResponse.headers().get(HeaderNames.LOCATION).value();
String redirectedUri = clientResponse.headers().get(HeaderNames.LOCATION).get();
URI newUri = URI.create(redirectedUri);
ClientUri redirectUri = ClientUri.create(newUri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ public void connect(URI uri, WsListener listener) {
+ responseHeaders);
}
ClientConnection connection = upgradeResponse.connection();
String secWsAccept = responseHeaders.get(HEADER_WS_ACCEPT).value();
String secWsAccept = responseHeaders.get(HEADER_WS_ACCEPT).get();
if (!hash(connection.helidonSocket(), secWsKey).equals(secWsAccept)) {
throw new WsClientException("Failed to upgrade to WebSocket, expected valid secWsKey. Headers: "
+ responseHeaders);
}
// we are upgraded, let's switch to web socket
if (headers.contains(HEADER_WS_PROTOCOL)) {
session = new ClientWsConnection(connection, listener, headers.get(HEADER_WS_PROTOCOL).value());
session = new ClientWsConnection(connection, listener, headers.get(HEADER_WS_PROTOCOL).get());
} else {
session = new ClientWsConnection(connection, listener);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -178,11 +178,11 @@ void test2PreFlightAllowedHeaders1() {

assertThat(response.status(), is(Status.OK_200));
assertThat(response.headers()
.get(ACCESS_CONTROL_ALLOW_ORIGIN).value(), is(fooOrigin()));
.get(ACCESS_CONTROL_ALLOW_ORIGIN).get(), is(fooOrigin()));
assertThat(response.headers()
.get(ACCESS_CONTROL_ALLOW_CREDENTIALS).value(), is("true"));
.get(ACCESS_CONTROL_ALLOW_CREDENTIALS).get(), is("true"));
assertThat(response.headers()
.get(ACCESS_CONTROL_ALLOW_METHODS).value(), is("PUT"));
.get(ACCESS_CONTROL_ALLOW_METHODS).get(), is("PUT"));
assertThat(response.headers()
.get(ACCESS_CONTROL_ALLOW_HEADERS).values(), containsString(fooHeader()));
assertThat(response.headers(), noHeader(ACCESS_CONTROL_MAX_AGE));
Expand All @@ -204,8 +204,8 @@ void test2PreFlightAllowedHeaders2() {
assertThat(response.headers(), hasHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "http://foo.bar"));
assertThat(response.headers(), hasHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"));
assertThat(response.headers(), hasHeader(ACCESS_CONTROL_ALLOW_METHODS, "PUT"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).value(), containsString("X-foo"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).value(), containsString("X-bar"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).get(), containsString("X-foo"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).get(), containsString("X-bar"));
assertThat(response.headers(), noHeader(ACCESS_CONTROL_MAX_AGE));
}
}
Expand All @@ -226,8 +226,8 @@ void test2PreFlightAllowedHeaders3() {
assertThat(response.headers(), hasHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "http://foo.bar"));
assertThat(response.headers(), hasHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"));
assertThat(response.headers(), hasHeader(ACCESS_CONTROL_ALLOW_METHODS, "PUT"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).value(), containsString("X-foo"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).value(), containsString("X-bar"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).get(), containsString("X-foo"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS).get(), containsString("X-bar"));
assertThat(response.headers(), noHeader(ACCESS_CONTROL_MAX_AGE));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public PeerInfo localPeer() {

@Override
public String authority() {
return headers.get(HeaderNames.HOST).value();
return headers.get(HeaderNames.HOST).get();
}

@Override
Expand Down
Loading

0 comments on commit 6a8700d

Please sign in to comment.