mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
user agent header (#5172)
* user agent in header * update user agent info * Use user-agent from lib
This commit is contained in:
parent
5e8e2a8312
commit
67ab1f69d8
@ -1,16 +1,19 @@
|
|||||||
"""Helper for aiohttp webclient stuff."""
|
"""Helper for aiohttp webclient stuff."""
|
||||||
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
from aiohttp.hdrs import USER_AGENT
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
|
from homeassistant.const import __version__
|
||||||
|
|
||||||
DATA_CONNECTOR = 'aiohttp_connector'
|
DATA_CONNECTOR = 'aiohttp_connector'
|
||||||
DATA_CONNECTOR_NOTVERIFY = 'aiohttp_connector_notverify'
|
DATA_CONNECTOR_NOTVERIFY = 'aiohttp_connector_notverify'
|
||||||
DATA_CLIENTSESSION = 'aiohttp_clientsession'
|
DATA_CLIENTSESSION = 'aiohttp_clientsession'
|
||||||
DATA_CLIENTSESSION_NOTVERIFY = 'aiohttp_clientsession_notverify'
|
DATA_CLIENTSESSION_NOTVERIFY = 'aiohttp_clientsession_notverify'
|
||||||
|
SERVER_SOFTWARE = 'HomeAssistant/{0} aiohttp/{1} Python/{2[0]}.{2[1]}'.format(
|
||||||
|
__version__, aiohttp.__version__, sys.version_info)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -28,7 +31,8 @@ def async_get_clientsession(hass, verify_ssl=True):
|
|||||||
connector = _async_get_connector(hass, verify_ssl)
|
connector = _async_get_connector(hass, verify_ssl)
|
||||||
clientsession = aiohttp.ClientSession(
|
clientsession = aiohttp.ClientSession(
|
||||||
loop=hass.loop,
|
loop=hass.loop,
|
||||||
connector=connector
|
connector=connector,
|
||||||
|
headers={USER_AGENT: SERVER_SOFTWARE}
|
||||||
)
|
)
|
||||||
_async_register_clientsession_shutdown(hass, clientsession)
|
_async_register_clientsession_shutdown(hass, clientsession)
|
||||||
hass.data[key] = clientsession
|
hass.data[key] = clientsession
|
||||||
@ -52,6 +56,7 @@ def async_create_clientsession(hass, verify_ssl=True, auto_cleanup=True,
|
|||||||
clientsession = aiohttp.ClientSession(
|
clientsession = aiohttp.ClientSession(
|
||||||
loop=hass.loop,
|
loop=hass.loop,
|
||||||
connector=connector,
|
connector=connector,
|
||||||
|
headers={USER_AGENT: SERVER_SOFTWARE},
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user