Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(server): remove crippled isLocaleAcceptable functionality (#1793)…
Browse files Browse the repository at this point in the history
…, r=@vbudhram, @rfk
  • Loading branch information
vbudhram authored Apr 5, 2017
1 parent d67d395 commit 748fcee
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 20 deletions.
8 changes: 1 addition & 7 deletions lib/metrics/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module.exports = log => {

return request.gatherMetricsContext({
event: event,
locale: marshallLocale(request),
locale: request.app && request.app.locale,
uid: coalesceUid(optionalData, request),
userAgent: request.headers['user-agent']
}).then(data => {
Expand Down Expand Up @@ -183,12 +183,6 @@ function optionallySetService (data, request) {
(request.query && request.query.service)
}

function marshallLocale (request) {
if (request.app && request.app.locale) {
return `${request.app.locale}${request.app.isLocaleAcceptable ? '' : '.default'}`
}
}

function coalesceUid (data, request) {
if (data && data.uid) {
return data.uid
Expand Down
8 changes: 1 addition & 7 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ function create(log, error, config, routes, db, translator) {

const acceptLanguage = trimLocale(request.headers['accept-language'])
request.app.acceptLanguage = acceptLanguage
const locale = translator.getLocale(acceptLanguage)
request.app.locale = locale
request.app.isLocaleAcceptable = isLocaleAcceptable(locale, acceptLanguage)
request.app.locale = translator.getLocale(acceptLanguage)

if (request.headers.authorization) {
// Log some helpful details for debugging authentication problems.
Expand Down Expand Up @@ -345,10 +343,6 @@ function create(log, error, config, routes, db, translator) {
return server
}

function isLocaleAcceptable (locale, acceptLanguage) {
return RegExp(`^(?:.+, *)*${locale}(?:[,-].+)*$`, 'i').test(acceptLanguage)
}

module.exports = {
create: create,
// Functions below exported for testing
Expand Down
2 changes: 0 additions & 2 deletions test/local/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe('lib/server', () => {
assert.ok(args[1])
assert.equal(args[1].path, '/account/create')
assert.equal(args[1].app.locale, 'en')
assert.equal(args[1].app.isLocaleAcceptable, true)
})

it('called log.summary correctly', () => {
Expand Down Expand Up @@ -150,7 +149,6 @@ describe('lib/server', () => {
assert.equal(log.begin.callCount, 1)
const args = log.begin.args[0]
assert.equal(args[1].app.locale, 'en')
assert.equal(args[1].app.isLocaleAcceptable, false)
})

it('called log.summary once', () => {
Expand Down
4 changes: 1 addition & 3 deletions test/local/metrics/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ describe('metrics/events', () => {
const metricsContext = mocks.mockMetricsContext()
const request = {
app: {
isLocaleAcceptable: false,
locale: 'en'
},
auth: {
Expand Down Expand Up @@ -204,7 +203,7 @@ describe('metrics/events', () => {
flow_id: 'bar',
flow_time: 1000,
flowCompleteSignal: 'account.signed',
locale: 'en.default',
locale: 'en',
time,
uid: 'deadbeef',
userAgent: 'foo'
Expand All @@ -226,7 +225,6 @@ describe('metrics/events', () => {
const metricsContext = mocks.mockMetricsContext()
const request = {
app: {
isLocaleAcceptable: true,
locale: 'fr'
},
clearMetricsContext: metricsContext.clear,
Expand Down
1 change: 0 additions & 1 deletion test/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ function mockRequest (data) {
app: {
acceptLanguage: 'en-US',
clientAddress: data.clientAddress || '63.245.221.32',
isLocaleAcceptable: true,
locale: data.locale || 'en-US'
},
auth: {
Expand Down

0 comments on commit 748fcee

Please sign in to comment.