Skip to content

Commit ff8ab76

Browse files
authored
feat: Added detection via http headers (#93)
1 parent 8c333ca commit ff8ab76

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

detectors/frameworks.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"js": "window.__NUXT__ || window.$nuxt || Boolean([...document.querySelectorAll('*')].find((el) => Boolean(el.__vue_app__?.$nuxt)))",
1515
"script": [
1616
"/_nuxt/"
17-
]
17+
],
18+
"headers": {
19+
"x-powered-by": "nuxt"
20+
}
1821
}
1922
},
2023
"vuepress": {

detectors/vue.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"script": [
55
"vue[.-]([\\d.]*\\d)[^/]*\\.js\\;version:\\1",
66
"(?:/([\\d.]+))?/vue(?:\\.min)?\\.js\\;version:\\1"
7-
]
7+
],
8+
"headers": {
9+
"x-powered-by": "nuxt"
10+
}
811
}

src/detectors.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ exports.getNuxtModules = async function (context) {
9393
return Array.from(modules)
9494
}
9595

96-
async function isMatching (detector, { originalHtml, html, scripts, page }) {
96+
async function isMatching (detector, { originalHtml, html, scripts, page, headers }) {
9797
// If we can detect technology from response html
9898
if (detector.originalHtml) {
9999
for (const pattern of parsePatterns(detector.originalHtml)) {
@@ -122,5 +122,13 @@ async function isMatching (detector, { originalHtml, html, scripts, page }) {
122122
} catch (e) {}
123123
}
124124
}
125+
// If we can detect technology from headers
126+
if (headers && detector.headers && typeof detector.headers === 'object' && Object.keys(detector.headers).length > 0) {
127+
for (const header of Object.keys(headers)) {
128+
if (Object.keys(detector.headers).find(key => key.toLowerCase() === header.toLowerCase())) {
129+
if (detector.headers[header].toLowerCase() === headers[header].toLowerCase()) return true
130+
}
131+
}
132+
}
125133
return false
126134
}

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function analyze (originalUrl, options = {}) {
5858
} else {
5959
domain = tldParser(url.origin).domain
6060
}
61-
61+
6262
const page = await browser.newPage()
6363
const infos = {
6464
url: originalUrl,
@@ -131,7 +131,7 @@ async function analyze (originalUrl, options = {}) {
131131
const html = await page.content()
132132

133133
// Use for detection
134-
const context = { originalHtml, html, scripts, page }
134+
const context = { originalHtml, html, scripts, page, headers }
135135

136136
if (!(await hasVue(context))) {
137137
const error = new Error(`Vue is not detected on ${originalUrl}`)

0 commit comments

Comments
 (0)