diff --git a/package.json b/package.json index d295c49..5b237d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@polymarket/clob-client", "description": "Typescript client for Polymarket's CLOB", - "version": "1.2.1", + "version": "1.2.2", "contributors": [ { "name": "Jonathan Amenechi", diff --git a/src/http-helpers/index.ts b/src/http-helpers/index.ts index 0309a8a..97415d8 100644 --- a/src/http-helpers/index.ts +++ b/src/http-helpers/index.ts @@ -1,12 +1,27 @@ import axios, { Method } from "axios"; import { FilterParams, TradeNotificationParams, TradeParams } from "src/types"; import { OpenOrderParams } from "../types"; +import { name, version } from "./../../package.json"; export const GET = "GET"; export const POST = "POST"; export const DELETE = "DELETE"; export const PUT = "PUT"; +const overloadHeaders = (method: Method, headers?: Record) => { + if (!headers || typeof headers === undefined) { + headers = {}; + } + headers!["User-Agent"] = `${name}@${version}`; + headers!["Accept"] = "*/*"; + headers!["Connection"] = "keep-alive"; + headers!["Content-Type"] = "application/json"; + + if (method === GET) { + headers!["Accept-Encoding"] = "gzip"; + } +}; + export const request = async ( endpoint: string, method: Method, @@ -15,6 +30,7 @@ export const request = async ( params?: any, ): Promise => { try { + overloadHeaders(method, headers); const response = await axios({ method, url: endpoint, headers, data, params }); return response; } catch (err) {