Added configurable user-agent for axios
Will use `mempool/v${backendInfo.getBackendInfo().version}` for default
			
			
This commit is contained in:
		
							parent
							
								
									9d5bbf1f44
								
							
						
					
					
						commit
						e41a08789a
					
				@ -18,6 +18,7 @@
 | 
			
		||||
    "EXTERNAL_ASSETS": [],
 | 
			
		||||
    "EXTERNAL_MAX_RETRY": 10,
 | 
			
		||||
    "EXTERNAL_RETRY_INTERVAL": 60,
 | 
			
		||||
    "USER_AGENT": "mempool",
 | 
			
		||||
    "STDOUT_LOG_MIN_PRIORITY": "debug"
 | 
			
		||||
  },
 | 
			
		||||
  "CORE_RPC": {
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ import { BisqBlocks, BisqBlock, BisqTransaction, BisqStats, BisqTrade } from './
 | 
			
		||||
import { Common } from '../common';
 | 
			
		||||
import { BlockExtended } from '../../mempool.interfaces';
 | 
			
		||||
import { StaticPool } from 'node-worker-threads-pool';
 | 
			
		||||
import backendInfo from '../backend-info';
 | 
			
		||||
import logger from '../../logger';
 | 
			
		||||
 | 
			
		||||
class Bisq {
 | 
			
		||||
@ -148,13 +149,22 @@ class Bisq {
 | 
			
		||||
  }
 | 
			
		||||
  private async updatePrice() {
 | 
			
		||||
    type axiosOptions = {
 | 
			
		||||
      headers: {
 | 
			
		||||
        'User-Agent': string
 | 
			
		||||
      };
 | 
			
		||||
      timeout: number;
 | 
			
		||||
      httpAgent?: http.Agent;
 | 
			
		||||
      httpsAgent?: https.Agent;
 | 
			
		||||
    }
 | 
			
		||||
    const setDelay = (secs: number = 1): Promise<void> => new Promise(resolve => setTimeout(() => resolve(), secs * 1000));
 | 
			
		||||
    const BISQ_URL = (config.SOCKS5PROXY.ENABLED === true) && (config.SOCKS5PROXY.USE_ONION === true) ? config.PRICE_DATA_SERVER.BISQ_ONION : config.PRICE_DATA_SERVER.BISQ_URL;
 | 
			
		||||
    const isHTTP = (new URL(BISQ_URL).protocol.split(':')[0] === 'http') ? true : false;
 | 
			
		||||
    const axiosOptions: axiosOptions = {};
 | 
			
		||||
    const axiosOptions: axiosOptions = {
 | 
			
		||||
      headers: {
 | 
			
		||||
        'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}`
 | 
			
		||||
      },
 | 
			
		||||
      timeout: config.SOCKS5PROXY.ENABLED ? 30000 : 10000
 | 
			
		||||
    };
 | 
			
		||||
    let retry = 0;
 | 
			
		||||
 | 
			
		||||
    if (config.SOCKS5PROXY.ENABLED) {
 | 
			
		||||
 | 
			
		||||
@ -55,7 +55,7 @@ class FiatConversion {
 | 
			
		||||
    const isHTTP = (new URL(fiatConversionUrl).protocol.split(':')[0] === 'http') ? true : false;
 | 
			
		||||
    const axiosOptions: axiosOptions = {
 | 
			
		||||
      headers: {
 | 
			
		||||
        'User-Agent': `mempool/v${backendInfo.getBackendInfo().version}`
 | 
			
		||||
        'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}`
 | 
			
		||||
      },
 | 
			
		||||
      timeout: config.SOCKS5PROXY.ENABLED ? 30000 : 10000
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,7 @@ interface IConfig {
 | 
			
		||||
    EXTERNAL_ASSETS: string[];
 | 
			
		||||
    EXTERNAL_MAX_RETRY: number;
 | 
			
		||||
    EXTERNAL_RETRY_INTERVAL: number;
 | 
			
		||||
    USER_AGENT: string;
 | 
			
		||||
    STDOUT_LOG_MIN_PRIORITY: 'emerg' | 'alert' | 'crit' | 'err' | 'warn' | 'notice' | 'info' | 'debug';
 | 
			
		||||
  };
 | 
			
		||||
  ESPLORA: {
 | 
			
		||||
@ -108,6 +109,7 @@ const defaults: IConfig = {
 | 
			
		||||
    'EXTERNAL_ASSETS': [],
 | 
			
		||||
    'EXTERNAL_MAX_RETRY': 10,
 | 
			
		||||
    'EXTERNAL_RETRY_INTERVAL': 60,
 | 
			
		||||
    'USER_AGENT': 'mempool',
 | 
			
		||||
    'STDOUT_LOG_MIN_PRIORITY': 'debug',
 | 
			
		||||
  },
 | 
			
		||||
  'ESPLORA': {
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
import axios, { AxiosResponse } from 'axios';
 | 
			
		||||
import * as fs from 'fs';
 | 
			
		||||
import config from './config';
 | 
			
		||||
import backendInfo from './api/backend-info';
 | 
			
		||||
import logger from './logger';
 | 
			
		||||
import { SocksProxyAgent } from 'socks-proxy-agent';
 | 
			
		||||
 | 
			
		||||
@ -42,6 +43,9 @@ class SyncAssets {
 | 
			
		||||
 | 
			
		||||
          logger.info(`Downloading external asset ${fileName} over the Tor network...`);
 | 
			
		||||
          return axios.get(url, {
 | 
			
		||||
            headers: {
 | 
			
		||||
              'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}`
 | 
			
		||||
            },
 | 
			
		||||
            httpAgent: agent,
 | 
			
		||||
            httpsAgent: agent,
 | 
			
		||||
            responseType: 'stream',
 | 
			
		||||
@ -57,6 +61,9 @@ class SyncAssets {
 | 
			
		||||
        } else {
 | 
			
		||||
          logger.info(`Downloading external asset ${fileName} over clearnet...`);
 | 
			
		||||
          return axios.get(url, {
 | 
			
		||||
            headers: {
 | 
			
		||||
              'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}`
 | 
			
		||||
            },
 | 
			
		||||
            responseType: 'stream',
 | 
			
		||||
            timeout: 30000
 | 
			
		||||
          }).then(function (response) {
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ import axios, { AxiosResponse } from 'axios';
 | 
			
		||||
import poolsParser from '../api/pools-parser';
 | 
			
		||||
import config from '../config';
 | 
			
		||||
import DB from '../database';
 | 
			
		||||
import backendInfo from '../api/backend-info';
 | 
			
		||||
import logger from '../logger';
 | 
			
		||||
import { SocksProxyAgent } from 'socks-proxy-agent';
 | 
			
		||||
import * as https from 'https';
 | 
			
		||||
@ -113,10 +114,19 @@ class PoolsUpdater {
 | 
			
		||||
   */
 | 
			
		||||
  private async query(path): Promise<object | undefined> {
 | 
			
		||||
    type axiosOptions = {
 | 
			
		||||
      headers: {
 | 
			
		||||
        'User-Agent': string
 | 
			
		||||
      };
 | 
			
		||||
      timeout: number;
 | 
			
		||||
      httpsAgent?: https.Agent;
 | 
			
		||||
    }
 | 
			
		||||
    const setDelay = (secs: number = 1): Promise<void> => new Promise(resolve => setTimeout(() => resolve(), secs * 1000));
 | 
			
		||||
    const axiosOptions: axiosOptions = {};
 | 
			
		||||
    const axiosOptions: axiosOptions = {
 | 
			
		||||
      headers: {
 | 
			
		||||
        'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}`
 | 
			
		||||
      },
 | 
			
		||||
      timeout: config.SOCKS5PROXY.ENABLED ? 30000 : 10000
 | 
			
		||||
    };
 | 
			
		||||
    let retry = 0;
 | 
			
		||||
 | 
			
		||||
    if (config.SOCKS5PROXY.ENABLED) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user