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 parser import RequestParser
|
||||
from gunicorn.http.message import Message, Request
|
||||
from gunicorn.http.parser import RequestParser
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
|
||||
import re
|
||||
# -*- coding: utf-8 -
|
||||
#
|
||||
# This file is part of gunicorn released under the MIT license.
|
||||
# See the NOTICE for more information.
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
from errors import *
|
||||
from gunicorn.http.errors import NoMoreData, ChunkMissingTerminator, \
|
||||
InvalidChunkSize
|
||||
|
||||
class ChunkedReader(object):
|
||||
def __init__(self, req, unreader):
|
||||
@ -147,9 +150,9 @@ class EOFReader(object):
|
||||
|
||||
data = self.unreader.read()
|
||||
while data:
|
||||
buf.write(data)
|
||||
if size is not None and buf.tell() > size:
|
||||
data = buf.getvalue()
|
||||
self.buf.write(data)
|
||||
if size is not None and self.buf.tell() > size:
|
||||
data = self.buf.getvalue()
|
||||
ret, rest = data[:size], data[size:]
|
||||
self.buf.truncate(0)
|
||||
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):
|
||||
pass
|
||||
@ -22,6 +26,13 @@ class InvalidRequestMethod(ParseException):
|
||||
|
||||
def __str__(self):
|
||||
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):
|
||||
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 urlparse
|
||||
|
||||
@ -8,8 +11,9 @@ try:
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
from body import ChunkedReader, LengthReader, EOFReader, Body
|
||||
from errors import *
|
||||
from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body
|
||||
from gunicorn.http.errors import InvalidHeader, InvalidHeaderName, NoMoreData, \
|
||||
InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion
|
||||
|
||||
class Message(object):
|
||||
def __init__(self, unreader):
|
||||
@ -72,7 +76,7 @@ class Message(object):
|
||||
try:
|
||||
clength = int(value)
|
||||
except ValueError:
|
||||
clenth = None
|
||||
clength = None
|
||||
elif name.upper() == "TRANSFER-ENCODING":
|
||||
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
|
||||
|
||||
from message import Request
|
||||
from unreader import SocketUnreader, IterUnreader
|
||||
from gunicorn.http.message import Request
|
||||
from gunicorn.http.unreader import SocketUnreader, IterUnreader
|
||||
|
||||
class Parser(object):
|
||||
def __init__(self, mesg_class, source):
|
||||
@ -25,7 +29,7 @@ class Parser(object):
|
||||
if self.mesg:
|
||||
data = self.mesg.body.read(8192)
|
||||
while data:
|
||||
data = mesg.body.read(8192)
|
||||
data = self.mesg.body.read(8192)
|
||||
|
||||
# Parse the next request
|
||||
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
|
||||
|
||||
|
||||
@ -3,11 +3,9 @@
|
||||
# This file is part of gunicorn released under the MIT license.
|
||||
# See the NOTICE for more information.
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
from urllib import unquote
|
||||
|
||||
@ -37,11 +35,11 @@ def create(req, sock, client, server, debug=False):
|
||||
if name == "expect":
|
||||
# handle expect
|
||||
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":
|
||||
forward_address = hdr_value
|
||||
forward = hdr_value
|
||||
elif name == "host":
|
||||
host = hdr_value
|
||||
server = hdr_value
|
||||
elif name == "script_name":
|
||||
script_name = hdr_value
|
||||
elif name == "content-type":
|
||||
|
||||
@ -74,6 +74,6 @@ class AsyncWorker(base.Worker):
|
||||
#Only send back traceback in HTTP in debug mode.
|
||||
if not self.debug:
|
||||
raise
|
||||
util.write_error(client, traceback.format_exc())
|
||||
util.write_error(sock, traceback.format_exc())
|
||||
return False
|
||||
return True
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user