Jaymon / endpoints

Lightweight REST api backend framework that automatically maps urls to python modules and classes
MIT License
29 stars 10 forks source link

File pointer failed with Daphne #122

Closed Jaymon closed 8 months ago

Jaymon commented 1 year ago

I was doing some quick prototyping using Daphne and I needed to serve a file so I created a controller like this:

class Assets(Controller):
    """Hack to allow files to be specified in a browser that doesn't allow them"""
    def GET(self, basename):
        fp = Filepath("whatever/path", basename)
        return fp.open()

This resulted in an infinite loop:

...
<DATETIME>,<PID> DEBUG    HTTP response chunk for ['<IP-ADDRESS>', 55030]
<DATETIME>,<PID> DEBUG    HTTP response chunk for ['<IP-ADDRESS>', 55030]
...

I'm not sure why, I switched fp.open() to fp.read_bytes() to fix it right now, but sometime in the future I should actually debug the problem.