Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #51 from zalando-incubator/50-fix-request-uri-parsing
Browse files Browse the repository at this point in the history
fix(fragment): Fixed x-zalando-request-uri parsing
  • Loading branch information
mfellner committed Jan 30, 2017
2 parents 9d724a4 + 72c17d6 commit bdac4c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/tessellate-fragment/src/actions/sources-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const SOURCES_QUERY_PARAM = 'sources'
const SOURCES_PROPERTY_BY_HEADER_KEY = {
'x-zalando-request-uri': {
key: 'bundles:path',
transformValue: (value) => {
const {hostname, pathname} = url.parse(value)
transformValue: (value, headers) => {
const { pathname } = url.parse(value)
const hostname = headers['x-zalando-request-host']
return path.join(hostname.replace(/^www\./, ''), pathname)
}
}
Expand Down Expand Up @@ -61,7 +62,7 @@ function assignSourcePropertiesFromHeaders(headers: Object, sources: Object) {
target = target[key]
}
const lastKey = keys.shift()
target[lastKey] = SOURCES_PROPERTY_BY_HEADER_KEY[headerName].transformValue(headers[headerName])
target[lastKey] = SOURCES_PROPERTY_BY_HEADER_KEY[headerName].transformValue(headers[headerName], headers)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ describe('sources-resolver', () => {
expect(sources.bundles.src).toBe('http://localhost:3001')
})

it('merges header properties with properties from nconf', async () => {
const headers = { 'x-zalando-request-uri': 'https://www.zalando.de/foo' }
it('merges headers with request uri and host with properties from nconf', async () => {
const headers = {
'x-zalando-request-uri': '/foo?q=bar',
'x-zalando-request-host': 'www.zalando.de'
}

const sources = await resolveSources(headers, {})

Expand All @@ -25,7 +28,10 @@ describe('sources-resolver', () => {
require('request-promise-native').mockImplementation(() =>
Promise.resolve({ sources: { bundles: { path: 'zalando.de/remote' } } }))

const headers = { 'x-zalando-request-uri': 'https://www.zalando.de/foo' }
const headers = {
'x-zalando-request-uri': '/foo',
'x-zalando-request-host': 'www.zalando.de'
}
const query = { sources: 'https://cdn.com/sources.json' }

const sources = await resolveSources(headers, query)
Expand Down

0 comments on commit bdac4c0

Please sign in to comment.