Skip to content

Commit

Permalink
pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dherault committed Jul 26, 2017
1 parent dc541a6 commit 889b640
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,35 @@ class Offline {
path: fullPath,
config: routeConfig,
handler: (request, reply) => { // Here we go

// Payload processing
request.payload = request.payload && request.payload.toString();

// Headers processing
// Hapi lowercases the headers whereas AWS does not
// So we recreate a custom headers object from the raw request
const unprocessedHeaders = {};

// so we recreate a custom headers object from the raw request
const headersArray = request.raw.req.rawHeaders;

for (let i = 0; i < headersArray.length; i += 2) {
unprocessedHeaders[headersArray[i]] = headersArray[i + 1];
// During tests, `server.inject` uses *shot*, a package
// for performing injections that does not entirely mimick
// Hapi's usual request object. rawHeaders are then missing
// Hence the fallback for testing

// Normal usage
if (headersArray) {
const unprocessedHeaders = {};

for (let i = 0; i < headersArray.length; i += 2) {
unprocessedHeaders[headersArray[i]] = headersArray[i + 1];
}

request.unprocessedHeaders = unprocessedHeaders;
}
// Lib testing
else {
request.unprocessedHeaders = request.headers;
console.log('request.unprocessedHeaders:', request.unprocessedHeaders);
}

request.unprocessedHeaders = unprocessedHeaders;

// Incomming request message
this.printBlankLine();
Expand Down
2 changes: 2 additions & 0 deletions test/support/RequestBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = class RequestBuilder {
this.request = {
method: method.toUpperCase(),
headers: {},
unprocessedHeaders: {},
params: {},
route: {
path,
Expand All @@ -19,6 +20,7 @@ module.exports = class RequestBuilder {

addHeader(key, value) {
this.request.headers[key] = value;
this.request.unprocessedHeaders[key] = value;
}

addBody(body) {
Expand Down

0 comments on commit 889b640

Please sign in to comment.