Skip to content

Commit

Permalink
Bug 1797449 - [websocket] Allow relative URLs and http(s) scheme r=va…
Browse files Browse the repository at this point in the history
…lentin

Add support to WebSocket for http: and https: URLs,
as well as having them be relative to a base URI.

Spec: whatwg/websockets#20

Passes new WPT tests for this in /websockets, with other tests unaffected.

Also updated our tests to expect these URLs to be successful instead of fail.

Differential Revision: https://phabricator.services.mozilla.com/D160330

UltraBlame original commit: e57780f6a56b73423be1fc35ef431877957bccae
  • Loading branch information
marco-c committed Jan 25, 2024
1 parent 6e6b3de commit 5d99145
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 674 deletions.
148 changes: 122 additions & 26 deletions dom/websocket/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,13 @@ nsIWebSocketImpl
h
"
#
include
"
nsIURIMutator
.
h
"
#
define
OPEN_EVENT_STRING
u
Expand Down Expand Up @@ -887,6 +894,9 @@ const
nsAString
&
aURL
nsIURI
*
aBaseURI
)
;
nsresult
Expand Down Expand Up @@ -4733,6 +4743,17 @@ return
true
;
}
nsIPrincipal
*
principal
=
mWorkerPrivate
-
>
GetPrincipal
(
)
;
mErrorCode
=
mImpl
Expand All @@ -4745,12 +4766,7 @@ jsapi
cx
(
)
mWorkerPrivate
-
>
GetPrincipal
(
)
principal
-
>
SchemeIs
Expand All @@ -4759,12 +4775,7 @@ SchemeIs
https
"
)
doc
-
>
NodePrincipal
(
)
principal
mClientInfo
mWorkerPrivate
-
Expand Down Expand Up @@ -7217,11 +7228,25 @@ IsSystemPrincipal
(
)
;
nsCOMPtr
<
nsIURI
>
baseURI
=
aPrincipal
-
>
GetURI
(
)
;
rv
=
ParseURL
(
aURL
baseURI
)
;
NS_ENSURE_SUCCESS
Expand Down Expand Up @@ -9239,6 +9264,9 @@ const
nsAString
&
aURL
nsIURI
*
aBaseURI
)
{
AssertIsOnMainThread
Expand Down Expand Up @@ -9297,6 +9325,8 @@ getter_AddRefs
uri
)
aURL
nullptr
aBaseURI
)
;
NS_ENSURE_SUCCESS
Expand Down Expand Up @@ -9324,18 +9354,17 @@ rv
NS_ERROR_DOM_SYNTAX_ERR
)
;
bool
hasRef
nsAutoCString
scheme
;
rv
=
parsedURL
-
>
GetHasRef
GetScheme
(
&
hasRef
scheme
)
;
NS_ENSURE_TRUE
Expand All @@ -9347,21 +9376,92 @@ rv
&
&
!
hasRef
scheme
.
IsEmpty
(
)
NS_ERROR_DOM_SYNTAX_ERR
)
;
nsAutoCString
if
(
scheme
=
=
"
http
"
|
|
scheme
=
=
"
https
"
)
{
scheme
=
scheme
=
=
"
https
"
?
"
wss
"
_ns
:
"
ws
"
_ns
;
NS_MutateURI
mutator
(
parsedURL
)
;
mutator
.
SetScheme
(
scheme
)
;
rv
=
mutator
.
Finalize
(
parsedURL
)
;
NS_ENSURE_SUCCESS
(
rv
NS_ERROR_DOM_SYNTAX_ERR
)
;
}
bool
hasRef
;
rv
=
parsedURL
-
>
GetScheme
GetHasRef
(
scheme
&
hasRef
)
;
NS_ENSURE_TRUE
Expand All @@ -9373,11 +9473,7 @@ rv
&
&
!
scheme
.
IsEmpty
(
)
hasRef
NS_ERROR_DOM_SYNTAX_ERR
)
;
Expand Down
42 changes: 42 additions & 0 deletions dom/websocket/tests/file_websocket_wsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,48 @@
"
test
-
1
"
or
request
.
ws_protocol
=
=
"
test
-
4
"
:

msgutil
.
send_message
(
request
"
server
data
"
)

msgutil
.
close_connection
(
request
)

elif
request
.
ws_protocol
=
=
"
test
-
2
.
1
Expand Down
Loading

0 comments on commit 5d99145

Please sign in to comment.