Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 'none+' serialization format as optional. #2241

Merged
merged 17 commits into from Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -178,9 +178,12 @@ void doClose() {

private URI normalizeUri(URI uri, Scheme scheme) {
if (isUndefinedUri(uri)) {
// See https://github.com/line/armeria/pull/2241 discussion for more details.
// We use a special singleton marker URI for clients that do not explicitly define a
// host or scheme at construction time.
// As this isn't created by users, we don't need to normalize it.
return uri;
}

if (scheme.serializationFormat() != SerializationFormat.NONE) {
rmohta marked this conversation as resolved.
Show resolved Hide resolved
return uri;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/linecorp/armeria/common/Scheme.java
Expand Up @@ -79,9 +79,9 @@ public static Optional<Scheme> tryParse(@Nullable String scheme) {
return Optional.empty();
}
final String lowercaseScheme = Ascii.toLowerCase(scheme);
final Optional<Scheme> parsedScheme = Optional.ofNullable(SCHEMES.get(lowercaseScheme));
if (parsedScheme.isPresent()) {
return parsedScheme;
final Scheme parsedScheme = SCHEMES.get(lowercaseScheme);
if (parsedScheme != null) {
return Optional.of(parsedScheme);
}
return Optional.ofNullable(SCHEMES.get(SerializationFormat.NONE.uriText() + '+' + lowercaseScheme));
}
Expand Down
Expand Up @@ -17,7 +17,9 @@
package com.linecorp.armeria.client;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import java.net.MalformedURLException;
import java.net.URI;

import org.junit.jupiter.api.Test;

Expand All @@ -33,9 +35,9 @@ void nonePlusSchemeProvided() {
}

@Test
void nonePlusSchemeUriToUrl() {
void nonePlusSchemeUriToUrl() throws MalformedURLException {
final HttpClient client = new ClientBuilder("none+https://google.com/").build(HttpClient.class);
assertThatCode(() -> client.uri().toURL()).doesNotThrowAnyException();
assertThat(client.uri().toURL()).isEqualTo(URI.create("https://google.com/").toURL());
}

@Test
Expand Down
19 changes: 15 additions & 4 deletions core/src/test/java/com/linecorp/armeria/common/SchemeTest.java
Expand Up @@ -21,6 +21,7 @@

import java.util.Optional;

import org.assertj.core.api.Condition;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -36,15 +37,25 @@ public void tryParse_null() {
@Test
void tryParse_add_none() {
final Optional<Scheme> got = Scheme.tryParse("http");
rmohta marked this conversation as resolved.
Show resolved Hide resolved
assertThat(got.get().serializationFormat()).isEqualTo(SerializationFormat.NONE);
assertThat(got.get().sessionProtocol()).isEqualTo(SessionProtocol.HTTP);
final Condition<Scheme> condition = new Condition<>(scheme ->
rmohta marked this conversation as resolved.
Show resolved Hide resolved
(scheme.sessionProtocol() ==
SessionProtocol.HTTP) &&
(scheme.serializationFormat() ==
SerializationFormat.NONE),
"none+http");
assertThat(got).hasValueSatisfying(condition);
}

@Test
void tryParse_with_none() {
final Optional<Scheme> got = Scheme.tryParse("http+none");
assertThat(got.get().serializationFormat()).isEqualTo(SerializationFormat.NONE);
assertThat(got.get().sessionProtocol()).isEqualTo(SessionProtocol.HTTP);
final Condition<Scheme> condition = new Condition<>(scheme ->
(scheme.sessionProtocol() ==
SessionProtocol.HTTP) &&
(scheme.serializationFormat() ==
SerializationFormat.NONE),
"none+http");
assertThat(got).hasValueSatisfying(condition);
}

@Test
Expand Down