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

Get host properly even if full URI is invalid #6072

Merged
merged 1 commit into from Apr 25, 2016

Conversation

gmethvin
Copy link
Member

Fixes #6066

This uses a regex since we are only trying to extract the host and port, and we don't really care if the rest of the URI is valid. I think this is a better solution than throwing an exception unexpectedly, especially since in many cases the host is just the value of the Host header and has nothing to do with the request URI.

@@ -26,6 +26,14 @@ class RequestHeaderSpec extends Specification {
val rh = DummyRequestHeader("GET", "https://example.com:8080/test", Headers(HOST -> "playframework.com"))
rh.host must_== "example.com:8080"
}
"absolute uri with port and invalid characters" in {
val rh = DummyRequestHeader("GET", "https://example.com:8080/classified-search/classifieds?version=GTI|V8", Headers(HOST -> "playframework.com"))
rh.host must_== "example.com:8080"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be consistent with java.net.URL?

scala> import java.net.URL
import java.net.URL

scala> val url = new URL("https://example.com:8080/classified-search/classifieds?version=GTI|V8")
url: java.net.URL = https://example.com:8080/classified-search/classifieds?version=GTI|V8

scala> url.getHost
res0: String = example.com

Copy link
Member Author

@gmethvin gmethvin Apr 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we're trying to get the host + port (that is what Host is in HTTP), so we need example.com:8080. rh.domain returns example.com.

@marcospereira marcospereira merged commit bc7b7e8 into playframework:master Apr 25, 2016
@marcospereira
Copy link
Member

Backport to 2.5.x: 898910d

@gmethvin gmethvin added this to the 2.5.3 milestone Apr 27, 2016
@gmethvin gmethvin deleted the uri branch December 9, 2016 11:24
@PatrickSauts PatrickSauts mentioned this pull request Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants