Skip to content

Commit

Permalink
Extract required HttpClient functions to dedicated interface (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
owenfarrell authored Dec 22, 2020
1 parent daea0b0 commit 9903060
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as _ from 'lodash';
import * as request from 'request';
import { v4 as uuidv4 } from 'uuid';
import { HttpClient, Request } from './http';
import { IHeaders, IOptions, ISecurity, SoapMethod, SoapMethodAsync } from './types';
import { IHeaders, IHttpClient, IOptions, ISecurity, SoapMethod, SoapMethodAsync } from './types';
import { findPrefix } from './utils';
import { WSDL } from './wsdl';
import { IPort, OperationElement, ServiceElement } from './wsdl/elements';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class Client extends EventEmitter {
public lastElapsedTime?: number;

private wsdl: WSDL;
private httpClient: HttpClient;
private httpClient: IHttpClient;
private soapHeaders: any[];
private httpHeaders: IHeaders;
private bodyAttributes: string[];
Expand Down
8 changes: 2 additions & 6 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import * as httpNtlm from 'httpntlm';
import * as req from 'request';
import * as url from 'url';
import {v4 as uuidv4} from 'uuid';
import { IHeaders, IOptions } from './types';
import { IExOptions, IHeaders, IHttpClient, IOptions } from './types';

const debug = debugBuilder('node-soap');
const VERSION = require('../package.json').version;

export interface IExOptions {
[key: string]: any;
}

export interface IAttachment {
name: string;
contentId: string;
Expand All @@ -33,7 +29,7 @@ export type Request = req.Request;
*
* @constructor
*/
export class HttpClient {
export class HttpClient implements IHttpClient {
private _request: req.RequestAPI<req.Request, req.CoreOptions, req.Options>;

constructor(options?: IOptions) {
Expand Down
12 changes: 10 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@

import * as req from 'request';
import { HttpClient } from './http';

export interface IHeaders {
[k: string]: any;
}

export interface IExOptions {
[key: string]: any;
}

export interface IHttpClient {
request(rurl: string, data: any, callback: (error: any, res?: any, body?: any) => any, exheaders?: IHeaders, exoptions?: IExOptions, caller?);
requestStream?(rurl: string, data: any, exheaders?: IHeaders, exoptions?: IExOptions, caller?): req.Request;
}

/** @deprecated use SoapMethod */
export type ISoapMethod = SoapMethod;
export type SoapMethod = (
Expand Down Expand Up @@ -112,7 +120,7 @@ export interface IOptions extends IWsdlBaseOptions {
/** set specific key instead of <pre><soap:Body></soap:Body></pre>. */
envelopeKey?: string;
/** provide your own http client that implements request(rurl, data, callback, exheaders, exoptions) */
httpClient?: HttpClient;
httpClient?: IHttpClient;
/** override the request module. */
request?: req.RequestAPI<req.Request, req.CoreOptions, req.RequiredUriUrl>;
stream?: boolean;
Expand Down

0 comments on commit 9903060

Please sign in to comment.