Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wreck#request's options are overridden by Defaults #117

Closed
ThisIsMissEm opened this issue Mar 2, 2016 · 2 comments
Closed

Wreck#request's options are overridden by Defaults #117

ThisIsMissEm opened this issue Mar 2, 2016 · 2 comments
Assignees
Labels
bug
Milestone

Comments

@ThisIsMissEm
Copy link
Contributor

@ThisIsMissEm ThisIsMissEm commented Mar 2, 2016

Essentially when you specify defaults, those override the individual values for each requests' options, rather than being, well, defaults.

Log of incorrect behaviour happening:

$ NODE_DEBUG=http node
> var Wreck = require('wreck')
undefined
> var Client = Wreck.defaults({ headers: { Accept: 'foo' }, baseUrl: "https://httpbin.org/" })
undefined
> Client.request('GET', '/get', { headers: { Accept: 'bar' }})
WRECK1 { headers: { Accept: 'bar' } }
WRECK2 { headers: { Accept: 'foo' }, baseUrl: 'https://httpbin.org/' }
HTTP 88774: call onSocket 0 0
HTTP 88774: createConnection httpbin.org:443::::::: { agent: 
   Agent {
     domain: 
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
     _events: { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { maxSockets: Infinity, path: null },
     requests: {},
     sockets: { 'httpbin.org:443:::::::': [] },
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } },
  headers: { Accept: 'foo' },
  method: 'GET',
  href: 'https://httpbin.org/get',
  path: null,
  pathname: '/get',
  query: null,
  search: null,
  hash: null,
  hostname: 'httpbin.org',
  port: 443,
  host: 'httpbin.org',
  auth: null,
  slashes: true,
  protocol: 'https:',
  _defaultAgent: 
   Agent {
     domain: 
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
     _events: { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: {},
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } },
  maxSockets: Infinity,
  servername: 'httpbin.org',
  _agentKey: 'httpbin.org:443:::::::' }
HTTP 88774: sockets httpbin.org:443::::::: 1
HTTP 88774: outgoing message end.
ClientRequest {
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] },
  _events: 
   { socket: { [Function: g] listener: [Function] },
     error: { [Function: g] listener: [Function] },
     response: { [Function: g] listener: [Function] } },
  _eventsCount: 3,
  _maxListeners: undefined,
  output: [ 'GET /get HTTP/1.1\r\nAccept: foo\r\nHost: httpbin.org\r\nConnection: close\r\n\r\n' ],
  outputEncodings: [ 'binary' ],
  outputCallbacks: [ [Function: finish] ],
  outputSize: 72,
  writable: true,
  _last: true,
  chunkedEncoding: false,
  shouldKeepAlive: false,
  useChunkedEncodingByDefault: false,
  sendDate: false,
  _removedHeader: {},
  _contentLength: 0,
  _hasBody: true,
  _trailer: '',
  finished: true,
  _headerSent: true,
  socket: null,
  connection: null,
  _header: 'GET /get HTTP/1.1\r\nAccept: foo\r\nHost: httpbin.org\r\nConnection: close\r\n\r\n',
  _headers: { accept: 'foo', host: 'httpbin.org' },
  _headerNames: { accept: 'Accept', host: 'Host' },
  _onPendingData: null,
  agent: 
   Agent {
     domain: 
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
     _events: { free: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { maxSockets: Infinity, path: null },
     requests: {},
     sockets: { 'httpbin.org:443:::::::': [Object] },
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256,
     maxCachedSessions: 100,
     _sessionCache: { map: {}, list: [] } },
  socketPath: undefined,
  method: 'GET',
  path: '/get',
  abort: [Function] }
> HTTP 88774: AGENT incoming response!
HTTP 88774: AGENT isHeadResponse false
HTTP 88774: CLIENT socket onClose
HTTP 88774: removeSocket httpbin.org:443::::::: destroyed: true
HTTP 88774: HTTP socket close

(note: WRECK1 / WRECK2 was me instrumenting Wreck around this line: https://github.com/hapijs/wreck/blob/master/lib/index.js#L69 )

  • Node.js version: v4.2.4
  • Wreck version: 7.0.0
@ThisIsMissEm

This comment has been minimized.

Copy link
Contributor Author

@ThisIsMissEm ThisIsMissEm commented Mar 2, 2016

In case it wasn't entirely clear here the line:

  output: [ 'GET /get HTTP/1.1\r\nAccept: foo\r\nHost: httpbin.org\r\nConnection: close\r\n\r\n' ],

Should read as:

  output: [ 'GET /get HTTP/1.1\r\nAccept: bar\r\nHost: httpbin.org\r\nConnection: close\r\n\r\n' ],
@ThisIsMissEm

This comment has been minimized.

Copy link
Contributor Author

@ThisIsMissEm ThisIsMissEm commented Mar 2, 2016

Looking at documentation for Hoek.applyToDefaultsWithShallow, I suspect the arguments have been placed around the wrong way on line 69 of Wreck.

ThisIsMissEm pushed a commit to ThisIsMissEm/wreck that referenced this issue Mar 2, 2016
ThisIsMissEm pushed a commit to ThisIsMissEm/wreck that referenced this issue Mar 2, 2016
@geek geek added the bug label Mar 2, 2016
@geek geek added this to the 7.0.1 milestone Mar 2, 2016
@geek geek self-assigned this Mar 2, 2016
@geek geek closed this Mar 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.