microsoft / typed-rest-client

Node Rest and Http Clients with typings for use with TypeScript
Other
675 stars 118 forks source link

Can't read body after GET with NTLM authentication #237

Closed awn70 closed 3 years ago

awn70 commented 4 years ago

Environment

Node version: 12.19.0 Npm version: 6.14.8 OS and version: Windows 10 (1909) typed-rest-client version: 1.7.3

Issue Description

I want to make a GET request to a server running a Spring Rest API. Authentication is done with NTLM. The response comes back with statusCode 200, when I call response.readBody() the client hangs. I can see the successfull authentication in the server log.

Expected behaviour

Get the body data (JSON).

Actual behaviour

Client hangs after call to readBody().

Code

const ntlmHandler: NtlmCredentialHandler = new NtlmCredentialHandler( "UUU", "PPP", "", "DDD" );
const httpClient: HttpClient = new HttpClient( "BWL", [ ntlmHandler ], { headers: { "Content-Type": "application/json" }, proxy: { proxyUrl: "" } } );
const response = await httpClient.get( `http://myserver:8080/api/parameter/`, { headers: { "Accept-Encoding": "identity" } } );
this.logger.debug( `Response code: ${response.message.statusCode} - ${response.message.statusMessage}` );
this.logger.debug( `Headers: ${JSON.stringify( response.message.headers )}` );
const result = await response.readBody();
this.logger.debug( `Body read: ${result}` );

Logs

NODE_DEBUG http log:

HTTP 6200: call onSocket 0 0
HTTP 6200: createConnection myserver:8080: {
  host: 'myserver',
  port: 8080,
  path: null,
  method: 'GET',
  headers: {
    'content-type': 'application/json',
    headers: { 'Accept-Encoding': 'identity' },
    'user-agent': 'BWL'
  },
  servername: 'myserver',
  _agentKey: 'myserver:8080:'
}
HTTP 6200: sockets myserver:8080: 1 1
HTTP 6200: outgoing message end.
HTTP 6200: AGENT incoming response!
HTTP 6200: call onSocket 0 0
HTTP 6200: createConnection myserver:8080: {
  headers: {
    Connection: 'keep-alive',
    Authorization: 'NTLM TlRMTVNTUAABAA...AAABBRw=='
  },
  timeout: 0,
  agent: Agent {
    _events: [Object: null prototype] {
      free: [Function],
      newListener: [Function: maybeEnableKeylog]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    defaultPort: 80,
    protocol: 'http:',
    options: { keepAlive: true, path: null },
    requests: {},
    sockets: { 'myserver:8080:': [] },
    freeSockets: {},
    keepAliveMsecs: 1000,
    keepAlive: true,
    maxSockets: Infinity,
    maxFreeSockets: 256,
    maxTotalSockets: Infinity,
    totalSocketCount: 0,
    [Symbol(kCapture)]: false
  },
  host: 'myserver',
  port: 8080,
  path: null,
  method: 'GET',
  username: 'UUU',
  password: 'PPP',
  domain: 'DDD',
  workstation: '',
  keepAlive: true,
  servername: 'myserver',
  _agentKey: 'myserver:8080:'
}
HTTP 6200: sockets myserver:8080: 1 1
HTTP 6200: outgoing message end.
HTTP 6200: CLIENT socket onClose
HTTP 6200: removeSocket myserver:8080: writable: false
HTTP 6200: HTTP socket close
HTTP 6200: AGENT incoming response!
HTTP 6200: AGENT socket keep-alive
HTTP 6200: CLIENT socket onFree
HTTP 6200: agent.on(free) myserver:8080:
HTTP 6200: removeSocket myserver:8080: writable: true
HTTP 6200: have free socket
HTTP 6200: outgoing message end.
HTTP 6200: AGENT incoming response!
HTTP 6200: AGENT socket.destroySoon()
[Nest] 6200   - 2020-11-05 11:15:20   [AdminController] Response code: 200 -
[Nest] 6200   - 2020-11-05 11:15:20   [AdminController] Headers: 
    {"set-cookie":["JSESSIONID=EE157C8...21E629; Max-Age=100; Expires=Thu, 05-Nov-2020 10:16:59 GMT; Path=/; HttpOnly"],
    "vary":"accept-encoding,origin,access-control-request-headers,access-control-request-method,accept-encoding",
    "x-frame-options":"SAMEORIGIN",
    "expires":"0",
    "x-content-type-options":"nosniff",
    "x-xss-protection":"1; mode=block",
    "cache-control":"no-cache, no-store, max-age=0, must-revalidate",
    "pragma":"no-cache",
    "content-type":"application/hal+json",
    "transfer-encoding":"chunked",
    "date":"Thu, 05 Nov 2020 10:15:19 GMT",
    "connection":"close"}
HTTP 6200: CLIENT socket onClose
HTTP 6200: removeSocket myserver:8080: writable: false
HTTP 6200: HTTP socket close
github-actions[bot] commented 3 years ago

This issue has had no activity in 90 days. Please comment if it is not actually stale

awn70 commented 3 years ago

Problem still exists...