diff --git a/src/handler.ts b/src/handler.ts index be48db4..6bae067 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -1,5 +1,4 @@ import { toLabels } from './headers' -import { ipInfo } from './ipinfo' import { referrer, shorten } from 'inbound' import { URL } from '@cliqz/url-parser' import { getName } from 'country-list' @@ -7,7 +6,6 @@ import { UAParser } from 'ua-parser-js' import { hash_hex, string_to_u8 } from 'siphash' import logfmt from 'logfmt' // import { parse } from './referer' -import { encode } from 'ngeohash' let sessionKey = string_to_u8(FINGERPRINT) @@ -30,7 +28,6 @@ const EXCLUDE = JSON.parse(OPTIONS) || { let batchedEvents: Array> = [] let currentHost: string | null = '' -let ipInfoQuotaReached = false const INCLUDE_LABELS = new Set([ 'method', @@ -161,6 +158,7 @@ async function handleRequest(event: FetchEvent): Promise { let parsed = new URL(url) let userAgent = request.headers.get('user-agent') + let countryCode = request.headers.get('cf-ipcountry') || 'unknown' parser.setUA(`${userAgent}`) @@ -182,12 +180,13 @@ async function handleRequest(event: FetchEvent): Promise { os_version: parser.getOS().version, // the ua-parser-js library identify desktop clients as an empty device type device_type: parser.getDevice().type ? parser.getDevice().type : 'desktop', - country: request.headers.get('cf-ipcountry'), + country: countryCode, type: '', network: '', client: '', referer_domain: '', duration, + country_name: getName(countryCode), } if (DEBUG_HEADERS) { @@ -199,21 +198,6 @@ async function handleRequest(event: FetchEvent): Promise { } } - if (ipInfoQuotaReached == false && clientIP.length > 0) { - try { - const ip = await ipInfo(clientIP) - - let geohash = encode(ip.lat, ip.lon) - let country_name = `${getName(ip.country)}` - - labels = { ...labels, ...ip, ...{ country_name, geohash } } - } catch (error) { - // We catched 429 Too Many Requests, this means that we reached our current - // ipinfo quota. Avoid making extra requests. - ipInfoQuotaReached = true - } - } - if (request.headers.get('referer')) { let refData: any = await new Promise((resolve) => { const ref = request.headers.get('referer') || '' diff --git a/test/handler.ts b/test/handler.ts index ba6b5b2..c340116 100644 --- a/test/handler.ts +++ b/test/handler.ts @@ -44,7 +44,6 @@ describe('request handler', () => { 'os="Mac OS"', 'device_type=desktop', 'country=US', - 'geohash=9yegjbpfr', 'country_name="United States of America"', 'method=GET', 'status=200', @@ -70,7 +69,6 @@ describe('request handler', () => { ) expect(bodyObj.streams[0].labels).to.not.include('url') - expect(bodyObj.streams[0].labels).to.not.include('geohash') expect(bodyObj.streams[0].labels).to.not.include('origin') }) @@ -149,7 +147,6 @@ describe('request handler', () => { // the referer of the original request is detected and parsed 'network=twitter', 'type=social', - 'geohash=9yegjbpfr', ].every((bit) => string.includes(bit)), ) })