sanic-org/sanic

User-agent parser / accessor on Request

开放

#2,744 创建于 2023年4月23日

 (3 条评论) (0 个反应) (0 位负责人)Python (1,515 个派生)batch import
feature requesthelp wantedintermediate

仓库指标

星标
 (17,623 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

The user-agent string is notoriously difficult to decipher. Suggesting to have request.user_agent with properties for browser and OS (in contrast to request.header.user_agent which is the raw header), alike to how we return the Accept header parsed. This would be useful for logging/statistics as well as to workaround certain browser incompatibilities that are otherwise not possible to test for strictly server-side.

Describe the solution you'd like

There are various ways to approach this, ranging from just returning the UA string but with the compatibility cruft removed (i.e. the way it should be if Internet wasn't broken), to providing separate accessors for browser, browser-version, platform, etc.

Additional context

https://pypi.org/project/httpagentparser/ https://github.com/pallets/werkzeug/blob/main/src/werkzeug/user_agent.py

贡献者指南