fix some errors & add headers. unitests still broken

This commit is contained in:
benoitc 2010-05-07 09:31:14 +02:00 committed by Paul J. Davis
parent c8154ea5fd
commit 516adafcbe
9 changed files with 50 additions and 22 deletions

View File

@ -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

View File

@ -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)

View File

@ -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):

View File

@ -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"

View File

@ -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)

View File

@ -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

View File

@ -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":

View File

@ -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

View File

@ -41,7 +41,7 @@ setup(
packages = find_packages(exclude=['examples', 'tests']),
include_package_data = True,
install_requires=['setuptools', 'simplehttp'],
install_requires=['setuptools'],
entry_points="""