Comments (6)
Oh, thanks for the investigation @antiphoton. I overestimated the degree to which UA strings can be accurately parsed. I'll withdraw my earlier comment (except to be mindful of more than two digits).
Maybe something like " Chrome/" or " Chromium/" (note the leading space) followed by any number of digits? No need for regex then, I suppose? std::string or nom will probably suffice?
from sxg-rs.
This should be a "denylist" approach -- allowing all user agents except those that match Chromium 73-78.
from sxg-rs.
I found a few UA parsers in crates, in descending popularity:
- woothee -- huge (820kB)
- uaparser -- huge (813kB)
- user-agent-parser
- uap-rust
- fast_uaparser
- device-detector
We should rule out the huge ones, since we have serverless bundle size constraints.
Perhaps a regex will suffice for our needs? Famous last words.
from sxg-rs.
I think a small heuristic without regex should be the way to go. For example, find Chrome/
or Chromium/
then get the next 2 digits to see if it is in [73, 78] range.
from sxg-rs.
Perhaps I'm a bit too forward-looking but there may eventually be a Chrome 730.
Are you concerned around new dependencies because of bundle size, security, performance, or something else?
In general, I prefer accurate parsers because inaccurate ones lead to weird ecosystem effects:
- sites begin to target bugs in the parsers, either deliberately (e.g. the IE star hack) or accidentally, and then
- changes to the standard need to keep in mind backwards-compatibility with these hacks, and then
- the semantics get progressively more complex (e.g. HTML adoption agency algorithm and others leading to cases where you can construct invalid DOMs)
That said, I'm also a pragmatist. In particular, sxg-rs is a drop in the bucket -- it probably won't materially effect the destiny of User-Agent.
from sxg-rs.
user-agent-parser, uap-rust and fast_uapperser are all internally using regular expressions defined in uap-core
.
Picking the Chrome-related regex in uap-core
is suffice to parse the Chrome major version.
However, adding regex
crate as dependency increases the gzipped WASM size from 737 kB to 954 kB.
from sxg-rs.
Related Issues (20)
- Add signed_host config param
- Lower SXG q-value for outgoing Accept header
- Flaky ACME integration test HOT 1
- Header integrity fetcher should not prefer SXG for subresources
- Current implementation will strip headers with same key HOT 2
- Content-Length header after transformation
- Create a reverse proxy server HOT 11
- Add AWS Lambda binding
- Add Netlify binding
- Add Vercel binding HOT 2
- Add Google Cloud Run binding
- Add Akamai binding HOT 11
- Remove wasm feature
- Switch Fastly ACME state to use Object Store
- Fastly: proxy unsigned on error
- Add backend_host config param
- Error out if `via: sxgrs`
- Set outer cache-control header
- Enable conditional responses HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sxg-rs.