254 Commits

Author SHA1 Message Date
Benoit Chesneau
26a796f200 Merge pull request #670 from gnotaras/bugfix-request-line-check
Fixed the request line length check.
2014-01-01 07:48:44 -08:00
Randall Leeds
56b5f4038f set wsgi.multithread to True for async workers
Also simplifies the environment handling in the gevent_pywsgi
server so that it also has this key. An added side effect is
that the gunicorn FileWrapper gets set for the gevent_pywsgi
worker, too.

Fixes #486
2014-01-01 16:42:56 +01:00
benoitc
640bf42206 don't send wsgi.errors twice and remove spurious print 2014-01-01 16:27:06 +01:00
benoitc
ee08ac8644 make sure to redirect wsgi.errors when needed
By if the options ` --error-logfile` is set to '-' then wsgi.errors are
returned to sys.stderr, if any log file is passed either using the
log-config file or the option, Errors are written to the files.

By default no error is returned.
2014-01-01 16:09:47 +01:00
benoitc
5fb4b49a91 dont' override SERVER_* by the Host header
Gunicorn shouln't override the SERVER_* by the Host header. The client
will take care about it during the URL reconstruction if needed.

Since the spec don't support unix sockets, Gunicorn is using the HOST
heeader when available to create viable SERVER_* if possible so the
application and framworks will be happy. When the Host Header is not
available (SocketPath, '') is returned.

fix #628
2014-01-01 14:05:59 +01:00
benoitc
c487368129 fix the correct remote address
The remote address should return the direct client addr not a forwarded
header.

This is a breaking change. The main problem with such changes is the way
the application or framework will handle the URL completion. Indeed most
of them are only expecting a TCP socket.

fix #633
2013-12-27 16:18:21 +01:00
benoitc
7d10d8638f fix sendfile with SSL 2013-12-26 14:14:48 +01:00
George Notaras
b9fe01ca2c Fixed the request line length check. 2013-12-19 03:18:18 +02:00
Neil Williams
9d9e547316 proxy_allow_ips: Allow proxy protocol if "*" specified.
This makes proxy_allow_ips symmetrical with forwarded_allow_ips and is
useful in the same situations.
2013-12-17 13:48:27 -08:00
Omer Katz
ce92230bd3 FileWrapper should inherit from object. 2013-12-01 16:08:37 +02:00
WooParadog
f22e6d4282 Error message should be able to be encoded in latin1
Broken request can have none latin1 characters which would break `util.write_error(client, status_int, reason, mesg)`
2013-11-13 14:28:38 +08:00
Alex Gaynor
b5c1810722 Only compiled some regexes used in HTTP parsing once
Currently they are parsed and compiled once per-HTTP request, which is
unnescary computation and makes stuff slower than it could be.
2013-08-28 20:23:53 -07:00
benoitc
25094605cf monkeypatch wsgi.sendfile for gevent
make sendfile usage non blocking with gevent
2013-08-27 18:18:35 +02:00
benoitc
dc97e54412 handle io.BytesIO object with file_wrapper
fix #595
2013-08-27 11:45:32 +02:00
benoitc
b3d85a0b67 optimise response connection header check
Get the status code from the response once so we can use it to check the need
for the connection header later without parsing the string each time we need it.
2013-08-12 11:39:11 +02:00
Dima Barsky
9f4cf4181f responses 1xx, 204 and 304 should not force the connection to be closed
Only these types of responses are allowed to have empty body

fix #581
2013-08-12 11:17:20 +02:00
benoitc
d29febdb28 fix "Expect: continue-100" support on python 3
only bytes should be passed to the socket.

fix #560
2013-06-29 05:22:27 +02:00
Andreas Stührk
fa7fd6fed0 Use a WSGI "bytes-as-unicode" string for PATH_INFO under Python 3. 2013-05-27 08:33:58 +02:00
Qiangning Hong
ec7f75f48f optimize readline()
Use less memory when processing file uploading, to be fast and safe
2013-01-06 18:49:30 +01:00
benoitc
030468d2cd don't accept str or unicode in the body. 2013-01-06 07:59:41 +01:00
Greg McGuire
02db7ecaad Set wsgi url_scheme to https if configured for SSL 2013-01-05 09:27:32 +01:00
Adnane Belmadiaf
20cd49595a PEP8 fixes 2012-12-24 09:53:03 +01:00
David Vincelli
c2ae9090dc handle size 0 read by returning empty buffer
It appears the original author meant to return b"" when size == 0 instead of raise ValueError("Size must be positive.")
2012-12-21 15:43:26 +01:00
benoitc
0b40e69e67 Merge branch 'develop' 2012-11-19 11:49:05 +01:00
benoitc
4da8f8067d str should be applied first.
change based on @sirkonst feedback
2012-11-16 11:12:57 +01:00
benoitc
46e041b9f1 don't use map 2012-11-16 11:08:02 +01:00
benoitc
91e7d138dc fix header encoding 2012-11-16 10:05:26 +01:00
benoitc
e4fbc805b6 fix error spotted by @andrewsg 2012-10-28 06:56:00 +01:00
mpaolini
7079fa033c allow bypassing of forwarded_allow_ips check 2012-10-26 14:45:23 +02:00
benoitc
f0deed1529 fix from @sirkonst feedback 2012-10-25 20:57:23 +02:00
benoitc
8d453fb341 all tests pass under python 3 2012-10-24 22:07:35 +02:00
benoitc
60644b12af miscellaneous fixes 2012-10-24 14:24:19 +02:00
benoitc
64371a0858 s/raise/reraise 2012-10-24 14:01:04 +02:00
benoitc
003c474fe2 handle bytes & native strings
This patch makes sure that we now handle correctly bytes and native
strings on python 3:

- In python 3, sockets are now taking and returning bytes.
- according to PEP3333, headers should be native strings and body in
  bytes.
2012-10-24 13:51:35 +02:00
benoitc
53ce50bc7b obvious syntax fixes preparing python3 support 2012-10-24 12:11:15 +02:00
Konstantin Kapustin
70534acde8 Implantation proxy protocol 2012-09-27 19:14:40 +02:00
Konstantin Kapustin
75933bae81 Change base-classes for NoMoreData, ChunkMissingTerminator and InvalidChunkSize.
If remote client send invalid data in request with "Transfer-Encoding:chunked" gunicorn can raised some exceptions (see http.body.ChunkedReader) as NoMoreData, ChunkMissingTerminator, InvalidChunkSize.

User application shouldn't know about specific gunicorn exceptions and must catch standard IOError if want.

Example:

    def app(env, start_response):

        body = env["wsgi.input"]

        chunk_size = 1024

        while True:
            try:
                chunk = body.read(chunk_size)
            except IOError:
                .. correct action for error

            if not chunk:
                break

            .. do somethink with chunk
2012-09-27 19:14:40 +02:00
Konstantin Kapustin
4be3282440 Check Content-Length header.
For not chunked request do validation Content-Length header and return 400 if invalid.
2012-09-27 19:14:40 +02:00
Konstantin Kapustin
d28366a683 Add ForwardedAllowIPS option. 2012-08-26 22:28:34 +02:00
Konstantin Kapustin
4fdfc3a76b Fix LimitRequestLine check. 2012-08-20 16:02:52 +04:00
benoitc
4b478e1a66 fix request line check. close #390
We never had the possibility to check the limit since we were quitting
the loop before it.
2012-08-03 06:27:26 +02:00
Paul J. Davis
489e935038 Fix request line length check
We were accidentally including partial data when we didn't find the
request line terminating '\r\n'. This changes the check to make sure
we're testing the length after we assert there's no termination.
2012-07-04 15:53:10 -05:00
benoitc
ffecd64669 don't finish the loop if the headers length is too big 2012-05-25 12:27:40 +02:00
benoitc
d79ff999ce fix multiple issues with request limit
patch from Djoume Salvetti . address the following issues in gunicorn:

* Gunicorn does not limit the size of a request header (the
* limit_request_field_size configuration parameter is not used)

* When the configured request limit is lower than its maximum value, the
* maximum value is used instead. For instance if limit_request_line is
* set to 1024, gunicorn will only limit the request line to 4096 chars
* (this issue also affects limit_request_fields)

* Request limits are not limited to their maximum authorized values. For
* instance it is possible to set limit_request_line to 64K (this issue
* also affects limit_request_fields)

* Setting limit_request_fields and limit_request_field_size to 0 does
* not make them unlimited. The following patch allows limit_request_line
* and limit_request_field_size to be unlimited. limit_request_fields can
* no longer be unlimited (I can't imagine 32K fields to not be enough
* but I have a use case where 8K for the request line is not enough).

* Parsing errors (premature client disconnection) are not reported

* When request line limit is exceeded the configured value is reported
* instead of the effective value.
2012-05-24 12:13:34 +02:00
Djoume Salvetti
9e308e317f Improves performance of http.body.Body.readline() 2012-05-10 11:24:54 +02:00
Benoit Chesneau
5f11713678 log HTTP errors in access log. close #317 2012-04-26 18:17:55 +02:00
benoitc
573ad019d1 fix websockets supports.
Thanks Nikolay Kim for the tests and patch.
2012-03-26 18:20:30 +02:00
benoitc
88cde80c9f remove spurious print 2012-03-01 08:24:00 +01:00
benoitc
a3a655928d fix keepalive response.
The expected response for keeep alive connections are Connection:
keep-alive not keepalive.
2012-03-01 08:22:58 +01:00
benoitc
1319543448 use the cached app. 2012-03-01 08:02:15 +01:00