Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caucase
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
caucase
Commits
d69c758a
Commit
d69c758a
authored
Jul 15, 2018
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: Make logging closer to apache default format
Escape all quoted strings. Add referrer. Add user-agent.
parent
de10e327
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
caucase/http.py
caucase/http.py
+38
-0
No files found.
caucase/http.py
View file @
d69c758a
...
...
@@ -93,6 +93,25 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
self
.
socket
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_V6ONLY
,
1
)
WSGIServer
.
server_bind
(
self
)
def
_buildQuoteCharList
():
# All chars considered guilty
result
=
[
'
\
\
x%02x'
%
x
for
x
in
xrange
(
256
)]
# Exception for non-printable whitespaces.
result
[
ord
(
'
\
b
'
)]
=
'
\
\
b'
result
[
ord
(
'
\
n
'
)]
=
'
\
\
n'
result
[
ord
(
'
\
r
'
)]
=
'
\
\
r'
result
[
ord
(
'
\
t
'
)]
=
'
\
\
t'
result
[
ord
(
'
\
v
'
)]
=
'
\
\
v'
# Exception for printable chars
for
x
in
xrange
(
0x20
,
0x7f
):
result
[
x
]
=
chr
(
x
)
# Exception in the exception: chars which need escapement
result
[
ord
(
'
\
\
'
)]
=
'
\
\
\
\
'
result
[
ord
(
'"'
)]
=
'
\
\
"'
return
result
_QUOTE_LOG_LIST
=
_buildQuoteCharList
()
del
_buildQuoteCharList
class
CaucaseWSGIRequestHandler
(
WSGIRequestHandler
):
"""
Make WSGIRequestHandler logging more apache-like.
...
...
@@ -114,6 +133,25 @@ class CaucaseWSGIRequestHandler(WSGIRequestHandler):
'%d/'
+
self
.
monthname
[
now
.
month
]
+
'/%Y:%H:%M:%S +0000'
,
)
def
log_request
(
self
,
code
=
'-'
,
size
=
'-'
):
"""
Log request. Happens after response was sent.
Compared to python(s default (from BaseHTTPServer):
- log referrer
- log user agent
- escaping
"""
headers
=
getattr
(
self
,
'headers'
,
{})
self
.
log_message
(
'"%s" %s %s "%s" "%s"'
,
''
.
join
(
_QUOTE_LOG_LIST
[
ord
(
x
)]
for
x
in
self
.
requestline
),
code
,
size
,
''
.
join
(
_QUOTE_LOG_LIST
[
ord
(
x
)]
for
x
in
headers
.
get
(
'Referrer'
,
'-'
)),
''
.
join
(
_QUOTE_LOG_LIST
[
ord
(
x
)]
for
x
in
headers
.
get
(
'User-Agent'
,
'-'
)),
)
class
CaucaseSSLWSGIRequestHandler
(
CaucaseWSGIRequestHandler
):
"""
Add SSL-specific entries to environ:
...
...
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