Parse task headers as HTTP headers rather than JSON

This commit is contained in:
Rowan Manning
2016-11-07 14:48:11 +00:00
committed by Rowan Manning
parent ee729d1d55
commit 568e068613
6 changed files with 24 additions and 12 deletions

View File

@@ -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
};