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

Expose response fields/methods #74

Closed gsakkis closed 9 months ago

gsakkis commented 7 years ago

The cresponse.Response class is currently completely opaque:

In [1]: from japronto.response.cresponse import Response
In [2]: resp = Response(code=204)
In [3]: resp.code
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-a60c9f6c40f4> in <module>()
----> 1 resp.code

AttributeError: 'cresponse.Response' object has no attribute 'code'

In [4]: dir(resp)
Out[4]: 
['__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__']

This prevents any kind of response introspection by middleware / handler decorators. Please expose at least the fields that a Response can be initialized with.