Decorates flask views and enrich User-Agent header in case of reduced UA string
Project description
Why it's needed
Starting Chrome 110 (https://developer.chrome.com/blog/user-agent-reduction-android-model-and-version/), Chrome reduced User-Agent string content sent by default by browsers in every request. The new UA string is will look like this:
Before: user-agent includes Android version and device model:
Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.0.0 Mobile Safari/537.36
After: reduced user-agent with fixed Android version and device model:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.0.0 Mobile Safari/537.36
This Flask wrapper tries to fix this by decorating a chosen Flask view, and if the fixed Android version and model are observed, it will trigger a refresh request from the browser but with the high entropy sec-ch-ua HTTP headers in the response, that can give us more information about the client (device model, OS version etc).
(You can read more about those Sec-CH-UA headers here https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues)
The response from the browser after the resent request will then have an enriched Flask request.user_agent including the correct device model and Android version, that can also be later parsed in any standard user-agent parsers libs or APIs
Quickstart
from flask import Flask, request
from flask_ua_enricher import SecChUa, resend_request_with_ch_ua
app = Flask(__name__)
sec_ch_ua = SecChUa()
sec_ch_ua.init_app(app)
@app.route('/helloChrome', methods=['GET'])
@resend_request_with_ch_ua
def hello():
return f"Hello with enriched UA: {request.user_agent.string}"
Note
If you're running this in a dev environment (i.e. your local PC), make sure to run your Flask server with HTTPS otherwise the enrichment won't work
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Flask-UA-Enricher-0.0.1.tar.gz.
File metadata
- Download URL: Flask-UA-Enricher-0.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44d13e9aec2c7ce34686e9ac0668d407e134b44c57282ce68f090b2f0d9d4acc
|
|
| MD5 |
8e5138bae7e46894eb8dfd3a186a7429
|
|
| BLAKE2b-256 |
06d3c18b27ddad896e12f20868ac9b7f1ce512d32a5decab67c84bfc301d554c
|
File details
Details for the file Flask_UA_Enricher-0.0.1-py3-none-any.whl.
File metadata
- Download URL: Flask_UA_Enricher-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3396b87c686e4597ddce2643756fba5e7e7f2c44a471529d87052766df501803
|
|
| MD5 |
4f005cbe8d8e8be37a3f06f0602fe796
|
|
| BLAKE2b-256 |
000bc2357b590982ca922ad43be8642196c2068e7f86846878c316f94eacd4da
|