Search code examples
pythongeventhttp-method

gevent.WSGIServer request method mystery


I'm getting some really strange behaviour when running gevent's WSGIServer. It seems like every request that comes through is having its method interpreted incorrectly..

If I send the following requests:

requests.get('http://localhost:5000')
requests.head('http://localhost:5000')
requests.delete('http://localhost:5000')
requests.put('http://localhost:5000')
requests.post('http://localhost:5000')

This is what appears in the console:

127.0.0.1 - - [2012-01-22 14:55:36] "POST / HTTP/1.1" 405 183 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:55:41] "DELETE / HTTP/1.1" 405 185 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:55:46] "16 / HTTP/1.1" 405 181 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:55:50] "8 / HTTP/1.1" 405 180 "-" "python-requests/0.9.1"
127.0.0.1 - - [2012-01-22 14:56:13] "HEAD / HTTP/1.1" 200 0 "-" "python-requests/0.9.1"

For completeness, this is the script I'm running:

from gevent.wsgi import WSGIServer
from flask import Flask

app = Flask(__name__)
app.debug = True

@app.route("/")
def hello():
    return 'hello'

port = 5000

http_server = WSGIServer(('', port), app)
http_server.serve_forever()

What could be going on?

Edit:

I'm using gevent version: 0.13.0


Solution

  • Libevent has a limited support for HTTP methods and which HTTP methods are supported depends on a libevent version. Why you have a number instead of a method is obviously a bug. Could it be that you're building and linking gevent against different versions?

    Can you try switching to gevent.pywsgi? That'll fix the issue at the cost of some performance.

    Also the 1.0 version of gevent has a number of great improvements. You can get it there: http://code.google.com/p/gevent/downloads/list