diff --git a/package.json b/package.json index b0150da..dfadab5 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "compression": "~1.6", "express": "~4.14", "express-hbs": "~1.0", + "http-headers": "^3.0.1", "moment": "~2.13", "pa11y-webservice": "^2.1.1", "pa11y-webservice-client-node": "^1.2.1", diff --git a/route/new.js b/route/new.js index 03b6a4b..7686d62 100644 --- a/route/new.js +++ b/route/new.js @@ -16,6 +16,7 @@ 'use strict'; const getStandards = require('../data/standards'); +const httpHeaders = require('http-headers'); module.exports = route; @@ -37,13 +38,11 @@ function route(app) { app.express.post('/new', (req, res) => { - let parsedHeaders = ''; - - try { - parsedHeaders = JSON.parse(req.body.headers); - } catch (e) { - console.log(`error parsing headers object: ${req.body.headers}. Ignoring.`); + let parsedHeaders; + if (req.body.headers) { + parsedHeaders = httpHeaders(req.body.headers, true); } + console.log(parsedHeaders); const newTask = { name: req.body.name, @@ -54,7 +53,7 @@ function route(app) { wait: req.body.wait || undefined, username: req.body.username || undefined, password: req.body.password || undefined, - headers: parsedHeaders || undefined, + headers: parsedHeaders, hideElements: req.body.hideElements || undefined }; diff --git a/route/task/edit.js b/route/task/edit.js index 4c2b185..ac73fa1 100644 --- a/route/task/edit.js +++ b/route/task/edit.js @@ -19,6 +19,7 @@ const presentTask = require('../../view/presenter/task'); const getStandards = require('../../data/standards'); +const httpHeaders = require('http-headers'); module.exports = route; @@ -56,12 +57,14 @@ function route(app) { if (err) { return next(); } + const originalHeaders = req.body.headers; req.body.ignore = req.body.ignore || []; req.body.timeout = req.body.timeout || undefined; req.body.wait = req.body.wait || undefined; req.body.username = req.body.username || undefined; req.body.password = req.body.password || undefined; req.body.hideElements = req.body.hideElements || undefined; + req.body.headers = httpHeaders(req.body.headers || '', true); app.webservice.task(req.params.id).edit(req.body, err => { if (err) { task.name = req.body.name; @@ -70,7 +73,7 @@ function route(app) { task.wait = req.body.wait; task.username = req.body.username; task.password = req.body.password; - task.headers = req.body.headers; + task.headers = originalHeaders; task.hideElements = req.body.hideElements; const standards = getStandards().map(standard => { if (standard.title === task.standard) { diff --git a/view/new.html b/view/new.html index 509499b..f5228db 100644 --- a/view/new.html +++ b/view/new.html @@ -105,8 +105,9 @@ along with Pa11y Dashboard. If not, see .
- - + + + (As key/value pairs, separated by newlines/colons)
diff --git a/view/presenter/task.js b/view/presenter/task.js index c4f9e3f..d2b34dc 100644 --- a/view/presenter/task.js +++ b/view/presenter/task.js @@ -35,6 +35,13 @@ function presentTask(task) { // Enhance the ignored rules task.ignore = presentIgnoreRules(task.ignore); + // Change headers to a string format + if (task.headers && typeof task.headers === 'object') { + task.headers = Object.keys(task.headers).map(header => { + return `${header}: ${task.headers[header]}`; + }).join('\n'); + } + // Present the last result if present if (task.last_result) { task.lastResult = presentResult(task.last_result); diff --git a/view/task/edit.html b/view/task/edit.html index be107af..bc564ad 100644 --- a/view/task/edit.html +++ b/view/task/edit.html @@ -117,8 +117,9 @@ along with Pa11y Dashboard. If not, see .
- - + + + (As key/value pairs, separated by newlines/colons)