首页 > 解决方案 > 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.

标签: node.jsproxyhubot

解决方案


pac+http通过使用协议来指定代理,我能够使代理“感知 pac” 。那成功了!

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)

推荐阅读