Search code examples
node.jsproxyhubot

Hubot: How to specify the agent to be used by robot.http


I am in a corporate environment with a proxy, so I am using the stanza mentioned in the Hubot documentation under "Forwarding all HTTP requests through a proxy".

proxy = require 'proxy-agent'
module.exports = (robot) ->
  robot.globalHttpOptions.httpAgent  = proxy('http://my-proxy-server.internal', false)
  robot.globalHttpOptions.httpsAgent = proxy('http://my-proxy-server.internal', true)

That does the trick and Hubot can reach the Internet.


EDIT: Another question popped up in the mean time. What is the second parameter to proxy (false for http and true for https) doing? I fail to find this in the documentation and the source code?


However, I also have some (internal) resources that cannot be reached via the proxy. So I have coffee scripts where I do not want to/cannot use the proxy...

The same bit of Hubot documentation (same section) also states:

For one-off control, use can specify an Agent to use with robot.http.

Disregarding what I think is a typo (use really should be you, I assume), I wonder how that can be done?

I basically want to disable the proxy for the requests from these "internal scripts". I tink that this should be possible by specifying that I want to use the default Agent. But how?

I tried about every thing I could come up with to no avail.


Solution

  • I was able to make the agent "pac aware" by using pac+http as the protocol to specify the proxy. That did the trick!

    proxy = require 'proxy-agent'
    module.exports = (robot) ->
      robot.globalHttpOptions.httpAgent  = proxy('pac+http://my-proxy-server.internal/proxy.pac', false)
      robot.globalHttpOptions.httpsAgent = proxy('pac+http://my-proxy- server.internal/proxy.pac', true)