Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
48ef9c08
Commit
48ef9c08
authored
Jul 29, 2007
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getHeader as it is in Zope3's HTTPRequest.
parent
8f11b96f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
lib/python/ZPublisher/HTTPRequest.py
lib/python/ZPublisher/HTTPRequest.py
+5
-2
lib/python/ZPublisher/tests/testHTTPRequest.py
lib/python/ZPublisher/tests/testHTTPRequest.py
+24
-0
No files found.
lib/python/ZPublisher/HTTPRequest.py
View file @
48ef9c08
...
...
@@ -1082,7 +1082,7 @@ class HTTPRequest(BaseRequest):
clone
[
'PARENTS'
]
=
[
self
[
'PARENTS'
][
-
1
]]
return
clone
def
get
_header
(
self
,
name
,
default
=
Non
e
):
def
get
Header
(
self
,
name
,
default
=
None
,
literal
=
Fals
e
):
"""Return the named HTTP header, or an optional default
argument or None if the header is not found. Note that
both original and CGI-ified header names are recognized,
...
...
@@ -1090,7 +1090,8 @@ class HTTPRequest(BaseRequest):
should all return the Content-Type header, if available.
"""
environ
=
self
.
environ
name
=
(
'_'
.
join
(
name
.
split
(
"-"
))).
upper
()
if
not
literal
:
name
=
name
.
replace
(
'-'
,
'_'
).
upper
()
val
=
environ
.
get
(
name
,
None
)
if
val
is
not
None
:
return
val
...
...
@@ -1098,6 +1099,8 @@ class HTTPRequest(BaseRequest):
name
=
'HTTP_%s'
%
name
return
environ
.
get
(
name
,
default
)
get_header
=
getHeader
# BBB
def
get
(
self
,
key
,
default
=
None
,
returnTaints
=
0
,
URLmatch
=
re
.
compile
(
'URL(PATH)?([0-9]+)$'
).
match
,
BASEmatch
=
re
.
compile
(
'BASE(PATH)?([0-9]+)$'
).
match
,
...
...
lib/python/ZPublisher/tests/testHTTPRequest.py
View file @
48ef9c08
...
...
@@ -801,6 +801,30 @@ class RequestTests( unittest.TestCase ):
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getClientAddr
(),
''
)
def
testGetHeader
(
self
):
s
=
StringIO
(
''
)
env
=
TEST_ENVIRON
.
copy
()
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getHeader
(
'Content-Type'
),
'multipart/form-data; boundary=12345'
)
# getHeader is agnostic of case
self
.
assertEqual
(
request
.
getHeader
(
'content-type'
),
'multipart/form-data; boundary=12345'
)
# and of dashes vs. underscores
self
.
assertEqual
(
request
.
getHeader
(
'content_type'
),
'multipart/form-data; boundary=12345'
)
# the 'literal' argument can turn this normalization off:
self
.
assertEqual
(
request
.
getHeader
(
'Content-Type'
,
literal
=
True
),
None
)
# the 'default' argument can be used to get something other than
# None when the lookup fails:
self
.
assertEqual
(
request
.
getHeader
(
'Not-existant'
,
default
=
'Whatever'
),
'Whatever'
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
AuthCredentialsTests
,
'test'
))
...
...
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