AsyncHTTPClient.configure doesnt seem to pass headers down to instances
Version 6.0.4 Mac Catalina 10.15.4
When I use httpclient.AsyncHTTPClient.configure to set default headers they dont seem to be passed down to instances of AsyncHTTPClient in later uses. The arg validate_cert is passed on to instances but the headers dont seem to be. The docs have me believing this should be working.
example code
import json
from tornado import ioloop, web, locks, httputil, httpclient
class Test(web.RequestHandler):
async def get(self):
try:
resp = await httpclient.AsyncHTTPClient().fetch('https://www.google.com')
print(resp.request.headers)
except httpclient.HTTPError as e:
print(e)
class TornadoApp(web.Application):
def __init__(self):
handlers = [
(r"/test", Test)
]
settings = dict(
debug=True
)
httpclient.AsyncHTTPClient.configure(None, defaults=dict(
headers=httputil.HTTPHeaders({"test_header": "test_value"})
))
super(TornadoApp, self).__init__(handlers, **settings)
async def main():
""" Main entry point for the tornado web server """
tornado_app = TornadoApp()
tornado_app.listen(8881)
await locks.Event().wait()
if __name__ == '__main__':
ioloop.IOLoop.current().run_sync(main)
The headers printed here are missing the 'test_header' header
Connection: close Host: www.google.com Accept-Encoding: gzip
You're right, this isn't working. The defaults are used when the request object has None, but there's always a non-None value for headers. There's not a clean simple way to fix this; we may just need to disallow headers in defaults.
Got it, thanks for looking at it