squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Unable to customize response object #75

Closed imgurbot12 closed 2 years ago

imgurbot12 commented 7 years ago

I was going through your source code for the module when i came across this file: https://github.com/squeaky-pl/japronto/blob/master/src/japronto/response/py.py

While the current commit comment for it claims its a "dead import", will there ever be a way to make a wrapper for the response object in the future? Ultimately, my goal is to change the way the response behaves and change the order in which the headers are returned.

Will there be anything like this in the future? Hopefully something like this:

from Japronto import Response

class NewResponse(Response):
    """
    Custom Japronto Response object
    """

    def __init__(self, *args, **kwargs):
        Response.__init__(self, *args, **kwargs)
        #custom code here

    def render(self):
        #custom code here
        pass
Snuggert commented 7 years ago

The python file you are referring to isn't actually used, also the dead import commit actually removed some dead import from the file as well as others.

The actual file used for the response object is here: https://github.com/squeaky-pl/japronto/blob/master/src/japronto/response/cresponse.c. Which can be imported as follows:

from japronto.response.cresponse import Response

Although it is possible to subclass a class implemented in C it would require some work by @squeaky-pl or another contributor who finds this important.

Snuggert commented 7 years ago

A reference guide can be found here: https://www.python.org/dev/peps/pep-0253/