Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
a68eff59
Commit
a68eff59
authored
Oct 16, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added attribute custom_headers to MixinHandler
parent
af60cd1c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
test_app.py
tests/test_app.py
+11
-3
handler.py
webssh/handler.py
+6
-1
No files found.
tests/test_app.py
View file @
a68eff59
...
@@ -586,22 +586,30 @@ class TestAppWithTrustedStream(OtherTestBase):
...
@@ -586,22 +586,30 @@ class TestAppWithTrustedStream(OtherTestBase):
class
TestAppNotFoundHandler
(
OtherTestBase
):
class
TestAppNotFoundHandler
(
OtherTestBase
):
custom_headers
=
handler
.
MixinHandler
.
custom_headers
def
test_with_not_found_get_request
(
self
):
def
test_with_not_found_get_request
(
self
):
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'GET'
)
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'GET'
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
'TornadoServer'
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
self
.
custom_headers
[
'Server'
]
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
def
test_with_not_found_post_request
(
self
):
def
test_with_not_found_post_request
(
self
):
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'POST'
,
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'POST'
,
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
'TornadoServer'
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
self
.
custom_headers
[
'Server'
]
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
def
test_with_not_found_put_request
(
self
):
def
test_with_not_found_put_request
(
self
):
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'PUT'
,
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'PUT'
,
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
'TornadoServer'
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
self
.
custom_headers
[
'Server'
]
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
webssh/handler.py
View file @
a68eff59
...
@@ -39,6 +39,10 @@ class InvalidValueError(Exception):
...
@@ -39,6 +39,10 @@ class InvalidValueError(Exception):
class
MixinHandler
(
object
):
class
MixinHandler
(
object
):
custom_headers
=
{
'Server'
:
'TornadoServer'
}
def
prepare
(
self
):
def
prepare
(
self
):
if
self
.
is_forbidden
():
if
self
.
is_forbidden
():
raise
tornado
.
web
.
HTTPError
(
403
)
raise
tornado
.
web
.
HTTPError
(
403
)
...
@@ -66,7 +70,8 @@ class MixinHandler(object):
...
@@ -66,7 +70,8 @@ class MixinHandler(object):
return
True
return
True
def
set_default_headers
(
self
):
def
set_default_headers
(
self
):
self
.
set_header
(
'Server'
,
'TornadoServer'
)
for
header
in
self
.
custom_headers
.
items
():
self
.
set_header
(
*
header
)
def
get_value
(
self
,
name
):
def
get_value
(
self
,
name
):
value
=
self
.
get_argument
(
name
)
value
=
self
.
get_argument
(
name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment