Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
6a080ea1
Unverified
Commit
6a080ea1
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Return an empty body for OPTIONS requests. (#7886)
parent
1ec688bf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/7886.misc
+1
-0
1 addition, 0 deletions
changelog.d/7886.misc
synapse/http/server.py
+5
-19
5 additions, 19 deletions
synapse/http/server.py
tests/test_server.py
+6
-6
6 additions, 6 deletions
tests/test_server.py
with
12 additions
and
25 deletions
changelog.d/7886.misc
0 → 100644
+
1
−
0
View file @
6a080ea1
Return an empty body for OPTIONS requests.
This diff is collapsed.
Click to expand it.
synapse/http/server.py
+
5
−
19
View file @
6a080ea1
...
@@ -442,21 +442,6 @@ class StaticResource(File):
...
@@ -442,21 +442,6 @@ class StaticResource(File):
return
super
().
render_GET
(
request
)
return
super
().
render_GET
(
request
)
def
_options_handler
(
request
):
"""
Request handler for OPTIONS requests
This is a request handler suitable for return from
_get_handler_for_request. It returns a 200 and an empty body.
Args:
request (twisted.web.http.Request):
Returns:
Tuple[int, dict]: http code, response body.
"""
return
200
,
{}
def
_unrecognised_request_handler
(
request
):
def
_unrecognised_request_handler
(
request
):
"""
Request handler for unrecognised requests
"""
Request handler for unrecognised requests
...
@@ -490,11 +475,12 @@ class OptionsResource(resource.Resource):
...
@@ -490,11 +475,12 @@ class OptionsResource(resource.Resource):
"""
Responds to OPTION requests for itself and all children.
"""
"""
Responds to OPTION requests for itself and all children.
"""
def
render_OPTIONS
(
self
,
request
):
def
render_OPTIONS
(
self
,
request
):
code
,
response_json_object
=
_options_handler
(
request
)
request
.
setResponseCode
(
204
)
request
.
setHeader
(
b
"
Content-Length
"
,
b
"
0
"
)
r
et
urn
respond_with_json
(
s
et
_cors_headers
(
request
)
request
,
code
,
response_json_object
,
send_cors
=
True
,
canonical_json
=
False
,
)
return
b
""
def
getChildWithDefault
(
self
,
path
,
request
):
def
getChildWithDefault
(
self
,
path
,
request
):
if
request
.
method
==
b
"
OPTIONS
"
:
if
request
.
method
==
b
"
OPTIONS
"
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_server.py
+
6
−
6
View file @
6a080ea1
...
@@ -193,10 +193,10 @@ class OptionsResourceTests(unittest.TestCase):
...
@@ -193,10 +193,10 @@ class OptionsResourceTests(unittest.TestCase):
return
channel
return
channel
def
test_unknown_options_request
(
self
):
def
test_unknown_options_request
(
self
):
"""
An OPTIONS requests to an unknown URL still returns 20
0 OK
.
"""
"""
An OPTIONS requests to an unknown URL still returns 20
4 No Content
.
"""
channel
=
self
.
_make_request
(
b
"
OPTIONS
"
,
b
"
/foo/
"
)
channel
=
self
.
_make_request
(
b
"
OPTIONS
"
,
b
"
/foo/
"
)
self
.
assertEqual
(
channel
.
result
[
"
code
"
],
b
"
20
0
"
)
self
.
assertEqual
(
channel
.
result
[
"
code
"
],
b
"
20
4
"
)
self
.
assert
Equal
(
channel
.
result
[
"
body
"
],
b
"
{}
"
)
self
.
assert
NotIn
(
"
body
"
,
channel
.
result
)
# Ensure the correct CORS headers have been added
# Ensure the correct CORS headers have been added
self
.
assertTrue
(
self
.
assertTrue
(
...
@@ -213,10 +213,10 @@ class OptionsResourceTests(unittest.TestCase):
...
@@ -213,10 +213,10 @@ class OptionsResourceTests(unittest.TestCase):
)
)
def
test_known_options_request
(
self
):
def
test_known_options_request
(
self
):
"""
An OPTIONS requests to an known URL still returns 20
0 OK
.
"""
"""
An OPTIONS requests to an known URL still returns 20
4 No Content
.
"""
channel
=
self
.
_make_request
(
b
"
OPTIONS
"
,
b
"
/res/
"
)
channel
=
self
.
_make_request
(
b
"
OPTIONS
"
,
b
"
/res/
"
)
self
.
assertEqual
(
channel
.
result
[
"
code
"
],
b
"
20
0
"
)
self
.
assertEqual
(
channel
.
result
[
"
code
"
],
b
"
20
4
"
)
self
.
assert
Equal
(
channel
.
result
[
"
body
"
],
b
"
{}
"
)
self
.
assert
NotIn
(
"
body
"
,
channel
.
result
)
# Ensure the correct CORS headers have been added
# Ensure the correct CORS headers have been added
self
.
assertTrue
(
self
.
assertTrue
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment