twisted / twisted/klein

Can't serve encoded (e.g. gzip) resources

Open
#55 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
838
Forks
123
Avg merge
7h 58m
Merged PRs (30d)
12

Description

There's this code in server.Request.process:

        try:
            resrc = self.site.getResourceFor(self)
            if resource._IEncodingResource.providedBy(resrc):
                encoder = resrc.getEncoder(self)
                if encoder is not None:
                    self._encoder = encoder
            self.render(resrc)
        except:
            self.processingFailed(failure.Failure())

And since Klein resources don't provide _IEncodingResource the resource is never asked for an encoder. So things like this serve but aren't gzipped:

class GzipFile(File):        
    def getChild(self, path, request):
        child = File.getChild(self, path, request)
        return EncodingResourceWrapper(child, [GzipEncoderFactory()])

class MainApp(object):

    app = Klein()

    @app.route('/static', branch=True)
    def static(self, request):
        return GzipFile('/tmp')

I'm not sure where the code goes that would allow serving gzipped data. I can easily duplicate what the GzipEncoder does in my own code, but it seems like a useful thing for klein to provide (or at least facilitate).

I'm happy to do the work if someone can point me toward where the code should go.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at server.Request.process, where Klein resources are checked for _IEncodingResource and rendered, and compare that path with the EncodingResourceWrapper and GzipEncoderFactory example in the issue. Trace how a routed resource reaches this code and determine how encoded resources should be recognized or supported; done means the example serves gzip-encoded data through Klein.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.