-
Notifications
You must be signed in to change notification settings - Fork 595
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
Conversation
…ive websocket request URIs
efbbd5b
to
b3191eb
Compare
Test PASSed. |
case ' ' if replaceSpaces ⇒ | ||
r ~~ '+'; 1 | ||
case c if c <= 127 && asciiCompatible ⇒ | ||
appendEncoded(c.toByte); 1 |
There was a problem hiding this comment.
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. 🤔
…ocket request URIs
Test FAILed. |
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. |
PLS BUILD |
Test PASSed. |
false | ||
} | ||
val defaultScheme = | ||
if (isWebsocket) (if (securedConnection) "wss" else "ws") |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@akka/akka-http-team any opinions on this one? |
There was a problem hiding this 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")))) |
There was a problem hiding this comment.
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
?
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.)
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Test FAILed. |
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) = |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Test FAILed. |
PLS BUILD |
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…fective websocket request URIs (akka#910)
fixes #909