From e65d557b4f1bd78cf6e80ccd74b54536c2574634 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 21 Jan 2016 22:41:56 +0100 Subject: [PATCH] Added request headers --- README.md | 5 +++-- es5-ff-spa-loader.js | 12 +++++++++--- package.json | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index aa2febb..65e299f 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ A javascript library providing server defined loading of assets for a single pag * server.assets = The server path to the assets resources definition file, is required (default: null) * server.timeout = The timeout to download the server resources. (default: 4096) * server.flag = The window flag which is set when the server.url is know. (default: 'FFServerUrl') + * server.header.request = An key value object with the request headers. (default: {'X-FFSpaLoader': 'sync'}) * question.transport = The transport to prefix the server.url with. (default: 'http://') * question.title = The question ui title. (default: 'Server') * question.text = The question ui text. (default: 'Please provide the server name;') @@ -155,7 +156,7 @@ A javascript library providing server defined loading of assets for a single pag ## Todo * test in production - * Server header set+check support + * Server header check support * Redo css(?divs) of server question * Add table+instance websql options so it can also be used in application code. * Add more tests @@ -175,7 +176,7 @@ Add unit tests for any new or changed functionality. Lint and test your code. * Added question.validate.[min|max|regex].value|message options. * Strip question value to hostname+port before use and validating. * Allow user upgrade to https in question input from default of transport option. - +* Added request headers setting. ### 0.0.4 * Added auto cache clean code diff --git a/es5-ff-spa-loader.js b/es5-ff-spa-loader.js index 685b3ba..2dffb28 100644 --- a/es5-ff-spa-loader.js +++ b/es5-ff-spa-loader.js @@ -69,10 +69,10 @@ timeout: 4096, flag: 'FFServerUrl', header: { - request: { // TODO: add header support - 'X-FFSpaLoader': '42' + request: { + 'X-FFSpaLoader': 'sync' }, - response: { + response: { // TODO: add header check support } } }, @@ -316,6 +316,12 @@ httpRequest.ontimeout = function() { cb('timeout after '+options.server.timeout+' of url '+url); }; + var headerKeys = Object.keys(options.server.header.request); + for (var headerKeyIdx in headerKeys) { + var headerKey = headerKeys[headerKeyIdx]; + var headerValue = options.server.header.request[headerKey]; + httpRequest.setRequestHeader(headerKey,headerValue); + } httpRequest.send(); }; diff --git a/package.json b/package.json index 9730757..5adee5b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Javascript Single Page Application Loader", "main": "es5-ff-spa-loader.js", "scripts": { - "prepublish": "gulp build", + "prepublish": "gulp build", "clean": "gulp clean", "build": "gulp build", "test": "gulp test" @@ -28,11 +28,11 @@ ], "license": "BSD-2-Clause", "repository": { - "type": "git", + "type": "git", "url": "https://bitbucket.org/im_ik/es5-ff-spa-loader.git" }, "bugs": { - "url": "https://bitbucket.org/im_ik/es5-ff-spa-loader/issues" + "url": "https://bitbucket.org/im_ik/es5-ff-spa-loader/issues" }, "devDependencies": { "gulp": "^3.9.0",