From a6900074c4066bf4e456a56fe1d1a783476b06bf Mon Sep 17 00:00:00 2001 From: petersirka Date: Fri, 1 Nov 2024 20:16:45 +0100 Subject: [PATCH] Revert "Improved user-agent parser (added support for new headers `Sec-CH-UA`)." This reverts commit 88571479c5083fa6cecb26ed090d1f0ac66f130b. --- changelog.txt | 1 - index.js | 2 +- utils.js | 16 ---------------- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/changelog.txt b/changelog.txt index 0bb848e..a4ce9c6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/index.js b/index.js index ff35774..457d507 100755 --- a/index.js +++ b/index.js @@ -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; } }); diff --git a/utils.js b/utils.js index 6170266..4d208bc 100755 --- a/utils.js +++ b/utils.js @@ -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;