2022-03-28 11:58:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2022 OzzieIsaacs
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2024-07-08 12:42:48 +00:00
|
|
|
from datetime import datetime
|
2022-03-28 11:58:41 +00:00
|
|
|
from gevent.pywsgi import WSGIHandler
|
|
|
|
|
2024-06-18 18:13:26 +00:00
|
|
|
|
2022-03-28 11:58:41 +00:00
|
|
|
class MyWSGIHandler(WSGIHandler):
|
|
|
|
def get_environ(self):
|
|
|
|
env = super().get_environ()
|
|
|
|
path, __ = self.path.split('?', 1) if '?' in self.path else (self.path, '')
|
|
|
|
env['RAW_URI'] = path
|
|
|
|
return env
|
|
|
|
|
2024-07-08 12:42:48 +00:00
|
|
|
def format_request(self):
|
|
|
|
now = datetime.now().replace(microsecond=0)
|
|
|
|
length = self.response_length or '-'
|
|
|
|
if self.time_finish:
|
|
|
|
delta = '%.6f' % (self.time_finish - self.time_start)
|
|
|
|
else:
|
|
|
|
delta = '-'
|
|
|
|
forwarded = self.environ.get('HTTP_X_FORWARDED_FOR', None)
|
|
|
|
if forwarded:
|
|
|
|
client_address = forwarded
|
|
|
|
else:
|
|
|
|
client_address = self.client_address[0] if isinstance(self.client_address, tuple) else self.client_address
|
|
|
|
return '%s - - [%s] "%s" %s %s %s' % (
|
|
|
|
client_address or '-',
|
|
|
|
now,
|
|
|
|
self.requestline or '',
|
|
|
|
# Use the native string version of the status, saved so we don't have to
|
|
|
|
# decode. But fallback to the encoded 'status' in case of subclasses
|
|
|
|
# (Is that really necessary? At least there's no overhead.)
|
|
|
|
(self._orig_status or self.status or '000').split()[0],
|
|
|
|
length,
|
|
|
|
delta)
|
2022-03-28 11:58:41 +00:00
|
|
|
|