Skip to content

Commit

Permalink
Revert "Improved user-agent parser (added support for new headers `Se…
Browse files Browse the repository at this point in the history
…c-CH-UA`)."

This reverts commit 8857147.
  • Loading branch information
petersirka committed Nov 1, 2024
1 parent 5a6d82b commit a690007
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 18 deletions.
1 change: 0 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- fixed partial validation
- fix image bug in the `Image.measureWEBP()` method by [Marek Mraz](https://github.com/Mrazbb)
- improved Markdown parser
- improved user-agent parser (added support for new headers `Sec-CH-UA`)

========================
0.0.97
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17343,7 +17343,7 @@ function extend_request(PROTO) {
Object.defineProperty(PROTO, 'ua', {
get: function() {
if (this.$ua === undefined)
this.$ua = U.parseUA(this.headers);
this.$ua = (this.headers['user-agent'] || '').parseUA();
return this.$ua;
}
});
Expand Down
16 changes: 0 additions & 16 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1685,22 +1685,6 @@ exports.isStaticFile = function(url) {
return index !== -1;
};

exports.parseUA = function(headers, structured) {
let ua = headers['sec-ch-ua'];
if (ua) {
let platform = headers['sec-ch-ua-platform'] || '';
let mobile = headers['sec-ch-ua-mobile'] === '?1';
let index = ua.indexOf('";v');
let browser = ua.substring(1, index);
if (platform)
platform = platform.substring(1, platform.length - 1);
return structured ? { os: platform, browser: browser, device: mobile ? 'mobile' : 'desktop' } : ((platform ? (platform + ' ') : '') + browser + (mobile ? ' Mobile' : ''));
} else {
ua = (headers['user-agent'] || '');
return ua ? ua.parseUA(structured) : ua;
}
};

exports.parseInt = function(obj, def) {
if (obj == null || obj === '')
return def === undefined ? 0 : def;
Expand Down

0 comments on commit a690007

Please sign in to comment.