Send 'Accept-Language' header on Nominatim API calls (#9501)

This commit is contained in:
Kyℓe Hensel
2023-03-04 06:34:24 +13:00
committed by GitHub
parent 0169abaffd
commit a17b5faf5f
2 changed files with 19 additions and 2 deletions
+13 -2
View File
@@ -3,6 +3,7 @@ import { json as d3_json } from 'd3-fetch';
import RBush from 'rbush';
import { geoExtent } from '../geo';
import { utilQsString } from '../util';
import { localizer } from '../core';
import { nominatimApiUrl } from '../../config/id.js';
@@ -56,7 +57,12 @@ export default {
var controller = new AbortController();
_inflight[url] = controller;
d3_json(url, { signal: controller.signal })
d3_json(url, {
signal: controller.signal,
headers: {
'Accept-Language': localizer.localeCodes().join(',')
}
})
.then(function(result) {
delete _inflight[url];
if (result && result.error) {
@@ -82,7 +88,12 @@ export default {
var controller = new AbortController();
_inflight[url] = controller;
d3_json(url, { signal: controller.signal })
d3_json(url, {
signal: controller.signal,
headers: {
'Accept-Language': localizer.localeCodes().join(',')
}
})
.then(function(result) {
delete _inflight[url];
if (result && result.error) {
+6
View File
@@ -75,6 +75,9 @@ describe('iD.serviceNominatim', function() {
expect(parseQueryString(fetchMock.calls()[0][0])).to.eql(
{zoom: '13', format: 'json', addressdetails: '1', lat: '49', lon: '17'}
);
expect(fetchMock.calls()[0][1].headers).to.eql({
'Accept-Language': 'en'
});
expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'cz'}});
done();
}, 50);
@@ -144,6 +147,9 @@ describe('iD.serviceNominatim', function() {
window.setTimeout(function() {
expect(parseQueryString(fetchMock.calls()[0][0])).to.eql({format: 'json', limit: '10'});
expect(fetchMock.calls()[0][1].headers).to.eql({
'Accept-Language': 'en'
});
expect(callback).to.have.been.calledOnce;
done();
}, 50);