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

Use ws(s) scheme instead of http(s) when calculating effective websocket request URIs #910

Merged
merged 6 commits into from
Jun 12, 2017

Conversation

aruediger
Copy link
Contributor

@aruediger aruediger commented Feb 28, 2017

fixes #909

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed validating PR that is currently being validated by Jenkins labels Feb 28, 2017
@akka-ci
Copy link

akka-ci commented Feb 28, 2017

Test PASSed.

case ' ' if replaceSpaces ⇒
r ~~ '+'; 1
case c if c <= 127 && asciiCompatible ⇒
appendEncoded(c.toByte); 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe these braces were present for a reason. 🤔

@aruediger aruediger requested a review from jrudolph March 2, 2017 10:33
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels Mar 4, 2017
@akka-ci
Copy link

akka-ci commented Mar 6, 2017

Test FAILed.

@jrudolph
Copy link
Member

jrudolph commented Mar 8, 2017

Wow, validation ran for 46 hours before it was interrupted. Let's try again...

And, sorry for not getting to review this any sooner, @2Beaucoup.

@jrudolph
Copy link
Member

jrudolph commented Mar 8, 2017

PLS BUILD

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR that is currently being validated by Jenkins labels Mar 8, 2017
@akka-ci
Copy link

akka-ci commented Mar 8, 2017

Test PASSed.

false
}
val defaultScheme =
if (isWebsocket) (if (securedConnection) "wss" else "ws")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could also add Uri.websocketScheme.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@aruediger
Copy link
Contributor Author

@akka/akka-http-team any opinions on this one?

Copy link
Member

@jlprat jlprat left a comment

Choose a reason for hiding this comment

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

not really into the topic, but it LGTM

test("/segment", "http://example.com/segment", Host("example.com"))
test("http://example.com/", "http://example.com/", Host("example.com"))
test("http://example.com:8080/", "http://example.com:8080/", Host("example.com", 8080))
test("/websocket", "ws://example.com/websocket", Host("example.com"), Upgrade(List(UpgradeProtocol("websocket"))))
Copy link
Member

Choose a reason for hiding this comment

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

Are there any the checks for https if so, you could add one also for wss?

Copy link
Member

@jrudolph jrudolph left a comment

Choose a reason for hiding this comment

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

Sorry @2Beaucoup for keeping that one hanging for so long. I agree with the goal of providing an effective URI for all kinds of requests.

As commented it would be nice not to introduce any extra processing to the common path.

@@ -365,7 +376,9 @@ object HttpRequest {
case 0 ⇒ // ok
case 4 if c(0) == 'h' && c(1) == 't' && c(2) == 't' && c(3) == 'p' ⇒ // ok
case 5 if c(0) == 'h' && c(1) == 't' && c(2) == 't' && c(3) == 'p' && c(4) == 's' ⇒ // ok
case _ ⇒ throw new IllegalArgumentException("""`uri` must have scheme "http", "https" or no scheme""")
case 2 if c(0) == 'w' && c(1) == 's' ⇒ // ok
case 3 if c(0) == 'w' && c(1) == 's' && c(2) == 's' ⇒ // ok
Copy link
Member

Choose a reason for hiding this comment

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

Scaladoc could be adapted to include "ws" and "wss" as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

false
}
val defaultScheme =
if (isWebsocket) (if (securedConnection) "wss" else "ws")
Copy link
Member

Choose a reason for hiding this comment

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

👍

case OptionVal.None ⇒ if (defaultHostHeader.isEmpty) fail("is missing a `Host` header") else defaultHostHeader
case OptionVal.Some(x) if x.isEmpty ⇒ if (defaultHostHeader.isEmpty) fail("an empty `Host` header") else defaultHostHeader
case OptionVal.Some(x) ⇒ x
}
uri.toEffectiveHttpRequestUri(host, port, securedConnection)
def isWebsocket: Boolean = {
Copy link
Member

Choose a reason for hiding this comment

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

Could we somehow prevent the extra scan through the header list? I'm not sure how critical it is but would be nice to prevent that every request has to go through it. (In the middle-term, we should probably try to evolve the HttpRequest model to include those kind of flags as I started to discuss in #991.)

Copy link
Contributor Author

@aruediger aruediger left a comment

Choose a reason for hiding this comment

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

@jrudolph updated. thanks for taking a look!

@@ -365,7 +376,9 @@ object HttpRequest {
case 0 ⇒ // ok
case 4 if c(0) == 'h' && c(1) == 't' && c(2) == 't' && c(3) == 'p' ⇒ // ok
case 5 if c(0) == 'h' && c(1) == 't' && c(2) == 't' && c(3) == 'p' && c(4) == 's' ⇒ // ok
case _ ⇒ throw new IllegalArgumentException("""`uri` must have scheme "http", "https" or no scheme""")
case 2 if c(0) == 'w' && c(1) == 's' ⇒ // ok
case 3 if c(0) == 'w' && c(1) == 's' && c(2) == 's' ⇒ // ok
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels May 10, 2017
@akka-ci
Copy link

akka-ci commented May 10, 2017

Test FAILed.

@jrudolph
Copy link
Member

PLS BUILD

OptionVal.None
}
val hostHeader: OptionVal[Host] = findHost(headers)
@tailrec def findHostAndWsUpgrade(it: Iterator[HttpHeader], host: OptionVal[Host] = OptionVal.None, wsUpgrade: Option[Boolean] = None): (OptionVal[Host], Boolean) =
Copy link
Member

Choose a reason for hiding this comment

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

wsUpgrade can be a Boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way it returns earlier if Upgrade.hasWebsocket == false but that's rather uncommon. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. Yes, let's keep it that way.

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) labels May 16, 2017
Copy link
Member

@jrudolph jrudolph left a comment

Choose a reason for hiding this comment

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

One small nitpick, otherwise, LGTM

@akka-ci akka-ci added needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR that is currently being validated by Jenkins labels May 16, 2017
@akka-ci
Copy link

akka-ci commented May 16, 2017

Test FAILed.

@jrudolph
Copy link
Member

PLS BUILD

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR that is currently being validated by Jenkins labels May 16, 2017
@akka-ci
Copy link

akka-ci commented May 16, 2017

Test PASSed.

Copy link
Member

@jrudolph jrudolph left a comment

Choose a reason for hiding this comment

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

LGTM

@jrudolph jrudolph merged commit ffe450d into master Jun 12, 2017
@jrudolph jrudolph deleted the 2beaucoup/ws-scheme branch June 12, 2017 14:29
tomrf1 pushed a commit to tomrf1/akka-http that referenced this pull request Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpMessage should contain websocket protocol in the effective request URI
4 participants