-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add context parsers for hybrid headers
- Pass on `x-podium-app-id` as `appId` on the context - Pass on `x-podium-base-font-size` as `baseFontSize` on the context - Override `deviceType` with `x-podium-device-type`
- Loading branch information
Showing
6 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default class PodiumContextAppIdParser { | ||
get [Symbol.toStringTag]() { | ||
return 'PodiumContextAppIdParser'; | ||
} | ||
|
||
/** | ||
* @param {import('@podium/utils').HttpIncoming} incoming | ||
* @returns {string | null} | ||
*/ | ||
parse(incoming) { | ||
let value = incoming.request.headers | ||
? incoming.request.headers['x-podium-app-id'] | ||
: null; | ||
if (!value || value === '') { | ||
return null; | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default class PodiumContextBaseFontSizeParser { | ||
get [Symbol.toStringTag]() { | ||
return 'PodiumContextBaseFontSizeParser'; | ||
} | ||
|
||
/** | ||
* @param {import('@podium/utils').HttpIncoming} incoming | ||
* @returns {string | null} | ||
*/ | ||
parse(incoming) { | ||
let value = incoming.request.headers | ||
? incoming.request.headers['x-podium-base-font-size'] | ||
: null; | ||
if (!value || value === '') { | ||
return null; | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ import Context from '../lib/context.js'; | |
|
||
const HEADER_RICH = { | ||
host: 'localhost:3030', | ||
'x-podium-app-id': '[email protected]', | ||
'x-podium-base-font-size': '1rem', | ||
'x-podium-device-type': 'mobile', | ||
'user-agent': | ||
'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36', | ||
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', | ||
|
@@ -236,6 +239,8 @@ tap.test( | |
t.equal(result.context['podium-mount-origin'], 'http://localhost:3030'); | ||
t.equal(result.context['podium-mount-pathname'], '/'); | ||
t.equal(result.context['podium-device-type'], 'mobile'); | ||
t.equal(result.context['podium-app-id'], '[email protected]'); | ||
t.equal(result.context['podium-base-font-size'], '1rem'); | ||
t.equal(result.context['podium-locale'], 'en-US'); | ||
t.equal(result.context['podium-debug'], 'false'); | ||
t.equal(result.context['podium-requested-by'], 'foo'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters