mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix some errors & add headers. unitests still broken
This commit is contained in:
parent
c8154ea5fd
commit
516adafcbe
@ -1,3 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
from message import Message, Request
|
from gunicorn.http.message import Message, Request
|
||||||
from parser import RequestParser
|
from gunicorn.http.parser import RequestParser
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
import re
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from errors import *
|
from gunicorn.http.errors import NoMoreData, ChunkMissingTerminator, \
|
||||||
|
InvalidChunkSize
|
||||||
|
|
||||||
class ChunkedReader(object):
|
class ChunkedReader(object):
|
||||||
def __init__(self, req, unreader):
|
def __init__(self, req, unreader):
|
||||||
@ -147,9 +150,9 @@ class EOFReader(object):
|
|||||||
|
|
||||||
data = self.unreader.read()
|
data = self.unreader.read()
|
||||||
while data:
|
while data:
|
||||||
buf.write(data)
|
self.buf.write(data)
|
||||||
if size is not None and buf.tell() > size:
|
if size is not None and self.buf.tell() > size:
|
||||||
data = buf.getvalue()
|
data = self.buf.getvalue()
|
||||||
ret, rest = data[:size], data[size:]
|
ret, rest = data[:size], data[size:]
|
||||||
self.buf.truncate(0)
|
self.buf.truncate(0)
|
||||||
self.buf.write(rest)
|
self.buf.write(rest)
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
class ParseException(Exception):
|
class ParseException(Exception):
|
||||||
pass
|
pass
|
||||||
@ -22,6 +26,13 @@ class InvalidRequestMethod(ParseException):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Invalid HTTP method: %r" % self.method
|
return "Invalid HTTP method: %r" % self.method
|
||||||
|
|
||||||
|
class InvalidHTTPVersion(ParseException):
|
||||||
|
def __init__(self, version):
|
||||||
|
self.version = version
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Invalid HTTP Version: %s" % self.version
|
||||||
|
|
||||||
class InvalidHeader(ParseException):
|
class InvalidHeader(ParseException):
|
||||||
def __init__(self, hdr):
|
def __init__(self, hdr):
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
@ -8,8 +11,9 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from body import ChunkedReader, LengthReader, EOFReader, Body
|
from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body
|
||||||
from errors import *
|
from gunicorn.http.errors import InvalidHeader, InvalidHeaderName, NoMoreData, \
|
||||||
|
InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion
|
||||||
|
|
||||||
class Message(object):
|
class Message(object):
|
||||||
def __init__(self, unreader):
|
def __init__(self, unreader):
|
||||||
@ -72,7 +76,7 @@ class Message(object):
|
|||||||
try:
|
try:
|
||||||
clength = int(value)
|
clength = int(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
clenth = None
|
clength = None
|
||||||
elif name.upper() == "TRANSFER-ENCODING":
|
elif name.upper() == "TRANSFER-ENCODING":
|
||||||
chunked = value.lower() == "chunked"
|
chunked = value.lower() == "chunked"
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from message import Request
|
from gunicorn.http.message import Request
|
||||||
from unreader import SocketUnreader, IterUnreader
|
from gunicorn.http.unreader import SocketUnreader, IterUnreader
|
||||||
|
|
||||||
class Parser(object):
|
class Parser(object):
|
||||||
def __init__(self, mesg_class, source):
|
def __init__(self, mesg_class, source):
|
||||||
@ -25,7 +29,7 @@ class Parser(object):
|
|||||||
if self.mesg:
|
if self.mesg:
|
||||||
data = self.mesg.body.read(8192)
|
data = self.mesg.body.read(8192)
|
||||||
while data:
|
while data:
|
||||||
data = mesg.body.read(8192)
|
data = self.mesg.body.read(8192)
|
||||||
|
|
||||||
# Parse the next request
|
# Parse the next request
|
||||||
self.mesg = self.mesg_class(self.unreader)
|
self.mesg = self.mesg_class(self.unreader)
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@ -3,11 +3,9 @@
|
|||||||
# This file is part of gunicorn released under the MIT license.
|
# This file is part of gunicorn released under the MIT license.
|
||||||
# See the NOTICE for more information.
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
import errno
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
|
|
||||||
@ -37,11 +35,11 @@ def create(req, sock, client, server, debug=False):
|
|||||||
if name == "expect":
|
if name == "expect":
|
||||||
# handle expect
|
# handle expect
|
||||||
if hdr_value.lower() == "100-continue":
|
if hdr_value.lower() == "100-continue":
|
||||||
self.socket.send("HTTP/1.1 100 Continue\r\n\r\n")
|
sock.send("HTTP/1.1 100 Continue\r\n\r\n")
|
||||||
elif name == "x-forwarded-for":
|
elif name == "x-forwarded-for":
|
||||||
forward_address = hdr_value
|
forward = hdr_value
|
||||||
elif name == "host":
|
elif name == "host":
|
||||||
host = hdr_value
|
server = hdr_value
|
||||||
elif name == "script_name":
|
elif name == "script_name":
|
||||||
script_name = hdr_value
|
script_name = hdr_value
|
||||||
elif name == "content-type":
|
elif name == "content-type":
|
||||||
|
|||||||
@ -74,6 +74,6 @@ class AsyncWorker(base.Worker):
|
|||||||
#Only send back traceback in HTTP in debug mode.
|
#Only send back traceback in HTTP in debug mode.
|
||||||
if not self.debug:
|
if not self.debug:
|
||||||
raise
|
raise
|
||||||
util.write_error(client, traceback.format_exc())
|
util.write_error(sock, traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -41,7 +41,7 @@ setup(
|
|||||||
packages = find_packages(exclude=['examples', 'tests']),
|
packages = find_packages(exclude=['examples', 'tests']),
|
||||||
include_package_data = True,
|
include_package_data = True,
|
||||||
|
|
||||||
install_requires=['setuptools', 'simplehttp'],
|
install_requires=['setuptools'],
|
||||||
|
|
||||||
entry_points="""
|
entry_points="""
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user