如何在WireMock中成功获取HTTPS端点代理? [英] How to get HTTPS endpoints to proxy successfully in WireMock?

查看:430
本文介绍了如何在WireMock中成功获取HTTPS端点代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个内部使用WireMock的HTTP记录回放代理,并且在记录HTTPS目标时遇到问题。 HTTP站点工作正常。

I am writing an HTTP record-playback proxy which internally uses WireMock, and am having a problem with recording HTTPS targets. HTTP sites work fine.

以下是我为未加密站点设置WireMock代理的方法:

Here is how I set up the WireMock proxy for an unencrypted site:

java \
    -jar /var/proximate/wiremock-standalone-2.4.1.jar \
    --port 9000 \
    --proxy-all http://ilovephp.jondh.me.uk \
    --record-mappings \
    --root-dir /remote/experiment/record/http

然后我可以使用此命令在该网站上记录任何内容:

I then can record anything on that site using this command:

wget -e use_proxy=yes -e http_proxy=proximate-proxy:9000 \
    http://ilovephp.jondh.me.uk/en/tutorial/make-your-own-blog

在短期内我会得到一些自动创建的映射:

In short order I will get some automatically created mappings:

/ # ls -R /remote/experiment/record/http
/remote/experiment/record/http:
__files   mappings

/remote/experiment/record/http/__files:
body-tutorial-make-your-own-blog-tWrNm.txt

/remote/experiment/record/http/mappings:
mapping-tutorial-make-your-own-blog-tWrNm.json

这是一回事,但在SSL网站上。代理优先:

Here is much the same thing, but on an SSL site. Proxy first:

java \
    -jar /var/proximate/wiremock-standalone-2.4.1.jar \
    --port 9000 \
    --proxy-all https://www.rottentomatoes.com/ \
    --record-mappings \
    --root-dir /remote/experiment/record/https \
    --verbose

这是获取:

wget -e use_proxy=yes -e http_proxy=proximate-proxy:9000 \
    https://www.rottentomatoes.com/

WireMock的结果是内部缓存目录是已创建,但它们不包含任何内容:

The result from WireMock is that the internal cache directories are created, but they do not contain anything:

/ # ls -R /remote/experiment/record/https
/remote/experiment/record/https:
__files   mappings

/remote/experiment/record/https/__files:

/remote/experiment/record/https/mappings:

我在Docker容器中使用Alpine 3.4上的WM 2.4.1。我是否需要使用一些 https -specific命令行开关才能使其正常工作?

I am using WM 2.4.1 on Alpine 3.4 in a Docker container. Do I need to use some of the https-specific command line switches to get this to work?

我暂时感到振奋,看到最近的发布 2.5.0 最近合并了 https-bind-address-bug ,听起来非常相关。我试过这个版本,但遗憾的是没有区别。

I was temporarily heartened to see that recent release 2.5.0 had a recent merge of https-bind-address-bug, which sounded very relevant. I have tried with this release, but unfortunately it makes no difference.

推荐答案

这部分解决了 - 我的主要错误是对于WireMock和客户端,HTTPS连接的代理地址是单独设置的。我现在正在使用:

This is partly solved - my main error was that the proxy address for HTTPS connections is set separately, for both WireMock and the client. I am now using:

java \
    -jar /var/proximate/wiremock-standalone-2.4.1.jar \
    --port 9000 \
    --https-port 9050 \
    --proxy-all https://www.rottentomatoes.com/ \
    --record-mappings \
    --root-dir /remote/experiment/record/https \
    --verbose \
    --print-all-network-traffic

我添加了 - print-all-network-traffic 所以我可以看到是否有任何HTTPS流量到达代理(现在是)。

I've added --print-all-network-traffic so I can see if any HTTPS traffic is hitting the proxy at all (it is now).

这是新的客户端命令,带有新代理指令:

Here is the new client command, complete with new proxy directive:

wget -e use_proxy=yes -e http_proxy=proximate-proxy:9000 \
     -e https_proxy=proximate-proxy:9050 \
     --verbose \
     --user-agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0" \
     https://www.rottentomatoes.com/

但是,现在实际上正在使用代理,看起来操作未成功完成。我尝试过其他加密网站并收到相同的模糊错误:

However, now the proxy is actually being used, it looks like the operation is not completing successfully. I've tried other encrypted sites and received the same vague errors:

Resolving proximate-proxy... 172.18.0.2
Connecting to proximate-proxy|172.18.0.2|:9050... connected.
Failed reading proxy response: No error information
Retrying.

--2017-01-26 09:20:18--  (try: 2)  https://www.rottentomatoes.com/
Connecting to proximate-proxy|172.18.0.2|:9050... connected.
Failed reading proxy response: No error information
Retrying.

--2017-01-26 09:20:20--  (try: 3)  https://www.rottentomatoes.com/
Connecting to proximate-proxy|172.18.0.2|:9050... connected.
Failed reading proxy response: No error information
Retrying.

^C

我已经更换了用户代理以防万一基于标准wget字符串的第三方拒绝,但这似乎也不会影响事情。

I have replaced the user agent in case there is some third-party rejection based on the standard "wget" string, but this does not seem to affect things either.

我会问一个关于此问题的新问题,以缩小范围这是WireMock还是Wget问题。

I will ask a new question about this, to narrow down whether this is a WireMock or a Wget problem.

这篇关于如何在WireMock中成功获取HTTPS端点代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆