Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website should work with wsgiref #289

Closed
chadwhitacre opened this issue Jan 30, 2014 · 2 comments
Closed

Website should work with wsgiref #289

chadwhitacre opened this issue Jan 30, 2014 · 2 comments

Comments

@chadwhitacre
Copy link
Contributor

I started building a little app using Aspen as a library instead of a server (see #283). I am unable to use wsgiref.simple_server, however. When I run the following and hit it ttw I get spinnage:

#!/usr/bin/env python                                                                                       
from aspen.website import Website                                                                           
from wsgiref.simple_server import make_server                                                               

make_server('0.0.0.0', 8080, Website()).serve_forever()

I believe the issue is from the fp.read call under _read_raw in request.py.

@chadwhitacre
Copy link
Contributor Author

I ended up getting the little app I was writing to work like so:

#!/usr/bin/env python
import os

from aspen import Response, resources
from aspen.website import Website
from wsgiref.simple_server import make_server


website = Website()
algorithm = website.algorithm


def total_hack(environ):
    # Workaround for https://github.com/gittip/aspen-python/issues/289

    class Dummy:
        def read(*a,**kw):
            return ''

    environ['wsgi.input'] = Dummy()


def favicon(request):
    if request.line.uri.path.raw == '/favicon.ico':
        raise Response(404)

IA_SPT = os.path.join(os.path.dirname(__file__), 'ia.spt')

def serve_ia_spt(request):
    request.fs = IA_SPT
    resource = resources.get(request)
    response = resource.respond(request)
    return {'response': response}


algorithm.functions = [ total_hack
                      , algorithm['parse_environ_into_request']
                      , algorithm['tack_website_onto_request']
                      , favicon
                      , serve_ia_spt
                      , algorithm['log_traceback_for_exception']
                       ]


server = make_server('0.0.0.0', os.environ.get('PORT', 8536), website)
server.serve_forever()

@pjz
Copy link
Contributor

pjz commented Mar 30, 2014

Yeah, it's because aspen is calling read() when there's 0 bytes waiting, so it blocks. Need to check content-length first to see how many bytes are expected, and read that many bytes.

@pjz pjz closed this as completed in 943cb8a Apr 1, 2014
chadwhitacre added a commit that referenced this issue Apr 1, 2014
Fix #289 - Website should work with wsgiref
Changaco pushed a commit that referenced this issue Mar 11, 2016
We were read()ing when there were no bytes expected,
which meant we blocked when we shouldn't have.
Changaco pushed a commit that referenced this issue Mar 11, 2016
Fix #289 - Website should work with wsgiref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants