Browse Source

Add support to change the user agent.

Godzil 5 years ago
parent
commit
a679573bf3
2 changed files with 11 additions and 1 deletions
  1. 1 0
      src/interface/IConfig.d.ts
  2. 10 1
      src/my_request.ts

+ 1 - 0
src/interface/IConfig.d.ts

@@ -22,6 +22,7 @@ interface IConfig {
   unlog?: boolean;
   retry?: number;
   // Login options
+  userAgent?: string;
   logUsingApi?: boolean;
   logUsingCookie?: boolean;
   crSessionUrl?: string;

+ 10 - 1
src/my_request.ts

@@ -183,6 +183,11 @@ export function get(config: IConfig, options: string|request.Options, done: (err
     loadCookies(config);
   }
 
+  if (config.userAgent)
+  {
+    defaultHeaders['User-Agent'] = config.userAgent;
+  }
+
   authenticate(config, (err) =>
   {
     if (err)
@@ -209,6 +214,11 @@ export function post(config: IConfig, options: request.Options, done: (err: Erro
     loadCookies(config);
   }
 
+  if (config.userAgent)
+  {
+    defaultHeaders['User-Agent'] = config.userAgent;
+  }
+
   authenticate(config, (err) =>
   {
     if (err)
@@ -375,7 +385,6 @@ function authenticate(config: IConfig, done: (err: Error) => void)
         });
       });
     }
-
   });
 }