forked from micronaut-projects/micronaut-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressing issue micronaut-projects#2283 where host is throwing NPE f…
…or some names where authority is required
- Loading branch information
coestre
committed
Oct 31, 2019
1 parent
f9c8a69
commit ec2178b
Showing
4 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
http-client/src/test/groovy/io/micronaut/http/client/DefaultHttpClientSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2017-2019 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.http.client | ||
|
||
import io.micronaut.http.client.loadbalance.FixedLoadBalancer | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class DefaultHttpClientSpec extends Specification { | ||
|
||
@Unroll | ||
def "Host header for #url is #expected"() { | ||
given: | ||
def balancer = new FixedLoadBalancer(new URL(url)) | ||
def configuration = new DefaultHttpClientConfiguration() | ||
|
||
when: | ||
def header = new DefaultHttpClient(balancer, configuration).getHostHeader(new URI(url)) | ||
|
||
then: | ||
header == expected | ||
|
||
where: | ||
url | expected | ||
"https://slave1-6x8-build-agent-2.0.1-5h7sl:8080" | "slave1-6x8-build-agent-2.0.1-5h7sl:8080" | ||
"https://foo_bar:8080" | "foo_bar:8080" | ||
"https://foobar:8080" | "foobar:8080" | ||
"http://foobar:8080" | "foobar:8080" | ||
"http://foobar" | "foobar" | ||
"http://foobar:80" | "foobar" | ||
"https://foobar:443" | "foobar" | ||
"https://service.url.com" | "service.url.com" | ||
"https://service.url.com:91" | "service.url.com:91" | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
http/src/test/groovy/io/micronaut/http/HttpRequestSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017-2019 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.http | ||
|
||
import spock.lang.Specification | ||
|
||
class HttpRequestSpec extends Specification { | ||
|
||
def "Converting to url and getting host and authority work as expected"() { | ||
expect: | ||
verifyAll { | ||
assert new URI("https://foo_bar").toString() == "https://foo_bar" | ||
assert HttpRequest.GET("https://localhost.company.com").getUri().toString() == "https://localhost.company.com" | ||
assert HttpRequest.GET("https://localhost").getUri().toString() == "https://localhost" | ||
assert HttpRequest.GET("https://foo_bar").getUri().toString() == "https://foo_bar" | ||
assert HttpRequest.GET("https://slave1-6x8-build-agent-2.0.1-5h7sl").getUri().toString() == "https://slave1-6x8-build-agent-2.0.1-5h7sl" | ||
assert HttpRequest.GET("https://slave1-6x8-build-agent-2.0.1-5h7sl:8080").getUri().toString() == "https://slave1-6x8-build-agent-2.0.1-5h7sl:8080" | ||
assert HttpRequest.GET(new URI("https://slave1-6x8-build-agent-2.0.1-5h7sl:8080")).getUri().toString() == "https://slave1-6x8-build-agent-2.0.1-5h7sl:8080" | ||
assert HttpRequest.GET(new URI("https://slave1-6x8-build-agent-2.0.1-5h7sl:8080")).getUri().getHost() == null | ||
assert HttpRequest.GET(new URI("https://slave1-6x8-build-agent-2.0.1-5h7sl:8080")).getUri().getAuthority() == "slave1-6x8-build-agent-2.0.1-5h7sl" | ||
} | ||
} | ||
} |