Commit 79a25437 authored by Denis Bilenko's avatar Denis Bilenko

wsgi: add SERVER_SOFTWARE in environ; use it for Server header

- the default value is "gevent x.y Python x.y"
parent d4a12a83
...@@ -2,9 +2,11 @@ import sys ...@@ -2,9 +2,11 @@ import sys
import traceback import traceback
from urllib import unquote from urllib import unquote
from datetime import datetime from datetime import datetime
from gevent.http import HTTPServer
socket = __import__('socket') socket = __import__('socket')
import gevent
from gevent.http import HTTPServer
__all__ = ['WSGIServer', __all__ = ['WSGIServer',
'WSGIHandler'] 'WSGIHandler']
...@@ -32,7 +34,7 @@ class WSGIHandler(object): ...@@ -32,7 +34,7 @@ class WSGIHandler(object):
def write(self, data): def write(self, data):
self.data.append(data) self.data.append(data)
def end(self): def end(self, env):
assert self.headers is not None, 'Application did not call start_response' assert self.headers is not None, 'Application did not call start_response'
has_content_length = False has_content_length = False
for k, v in self.headers: for k, v in self.headers:
...@@ -51,6 +53,10 @@ class WSGIHandler(object): ...@@ -51,6 +53,10 @@ class WSGIHandler(object):
# QQQ end of work around # QQQ end of work around
# QQQ when this is fixed, add version guard # QQQ when this is fixed, add version guard
SERVER_SOFTWARE = env.get('SERVER_SOFTWARE')
if SERVER_SOFTWARE and not self.request.find_output_header('Server'):
self.request.add_output_header('Server', SERVER_SOFTWARE)
self.send_reply(self.code, self.reason, data) self.send_reply(self.code, self.reason, data)
def send_reply(self, code, reason, data): def send_reply(self, code, reason, data):
...@@ -110,15 +116,16 @@ class WSGIHandler(object): ...@@ -110,15 +116,16 @@ class WSGIHandler(object):
return return
finally: finally:
if self is not None: if self is not None:
self.end() self.end(env)
class WSGIServer(HTTPServer): class WSGIServer(HTTPServer):
handler_class = WSGIHandler handler_class = WSGIHandler
base_env = {'SCRIPT_NAME': '', base_env = {'GATEWAY_INTERFACE': 'CGI/1.1',
'GATEWAY_INTERFACE': 'CGI/1.1', 'SERVER_SOFTWARE': 'gevent/%d.%d Python/%d.%d' % (gevent.version_info[:2] + sys.version_info[:2]),
'SCRIPT_NAME': '',
'wsgi.version': (1, 0), 'wsgi.version': (1, 0),
'wsgi.url_scheme': 'http', 'wsgi.url_scheme': 'http',
'wsgi.errors': sys.stderr, 'wsgi.errors': sys.stderr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment