Skip to content

Commit 504ef38

Browse files
committed
Merge pull request #975 from Martii/Issue-944acceptRejects
Add a base 406 not acceptable Auto-merge
2 parents 56cdd79 + 352ffd5 commit 504ef38

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

controllers/scriptStorage.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ exports.sendScript = function (aReq, aRes, aNext) {
211211
let accept = aReq.headers.accept;
212212
let accepts = null;
213213
let hasAcceptUserScriptMeta = false;
214+
let hasAcceptNotAcceptable = false;
214215
let url = URL.parse(aReq.url);
215216

216217
let isLib = aReq.params.isLib || /^\/libs\//.test(url.pathname);
@@ -221,10 +222,32 @@ exports.sendScript = function (aReq, aRes, aNext) {
221222
if (accept) {
222223
accepts = accept.split(',');
223224
accepts.forEach(function (aElement, aIndex, aArray) {
224-
if (/^text\/x\-userscript\-meta/.test(aElement.trim())) { // TODO: toggle `\-meta` in re
225+
let acceptItem = aElement.trim();
226+
227+
if (/^text\/x\-userscript\-meta/.test(acceptItem)) { // TODO: toggle `\-meta` in re
225228
hasAcceptUserScriptMeta = true;
226229
}
230+
231+
// Find 406 (not acceptables)
232+
if (/^image\//.test(acceptItem)) {
233+
hasAcceptNotAcceptable = true;
234+
}
235+
227236
});
237+
} else {
238+
console.warn([
239+
'WARNING:',
240+
' ' + aReq.connection.remoteAddress,
241+
' ' + aReq.headers.accept,
242+
' ' + aReq._parsedUrl.pathname,
243+
' ' + aReq.headers['user-agent']
244+
].join('\n'));
245+
}
246+
247+
// Test for 406 (not acceptables)
248+
if (hasAcceptNotAcceptable && rUserJS.test(url.pathname)) {
249+
aRes.status(406).send();
250+
return;
228251
}
229252

230253
if (hasAcceptUserScriptMeta && rUserJS.test(url.pathname) ||

0 commit comments

Comments
 (0)