node.js - 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.
解决方案
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)
推荐阅读
- lua - Roblox 中的“尝试使用 'Connect' 索引函数”是什么意思?
- visual-studio - 如何修复有关这些错误消息的命令提示错误?
- mysql - SQL 检查是否存在非唯一记录——如果存在,则更新;如果不是,则将记录插入表中
- node.js - Heroku 在尝试使用 https 时出现“连接关闭且没有响应”错误
- c# - 如何将位于应用程序部分 (DLL) 中的部分视图呈现到主 asp.net core 2.2 项目中
- node.js - 将数据从 EJS 中的 Span 发送到服务器 Nodejs
- java - 在java中以模式打印数组
- python-requests - python - 如何在多进程池中回收来自单个requests.Session对象的请求的连接?
- acumatica - 网格内的字段过滤器
- css - 无法弄清楚为什么当 div 折叠时我的 div 内的内容会被挤压