如何使 browsermob-proxy 记录所有响应正文

我使用 browsermob-proxy 的 har 导出功能遇到了问题。一些响应正文没有被记录(整个 "text" 字段都缺失了)

我的设置(使用 browsermob-proxy 2.1.4)

curl -X POST http://localhost:8080/proxy?port=9091

curl -X PUT "http://localhost:8080/proxy/9091/har?captureHeaders=true&captureCookies=true&captureContent=true"

有些响应正常:

"response": { "status": 201, "statusText": "Created", "httpVersion": "HTTP/1.1", "cookies": [], "headers": [{ "name": "Cache-Control", "value": "max-age=0, no-cache, no-store" }, { "name": "Content-Type", "value": "application/json" }, { "name": "Date", "value": "Thu, 15 Feb 2018 13:07:39 GMT" }, { "name": "Location", "value": ... }, { "name": "Pragma", "value": "no-cache" }, { "name": "Render-Time", "value": "8" }, { "name": "Server", "value": "openresty" }, { "name": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains" }, { "name": "transfer-encoding", "value": "chunked" }, { "name": "Connection", "value": "keep-alive" }], "content": { "size": 8607, "mimeType": "application/json", "text": "{ <actual json body> }", "comment": "" }, ...

但有些不正常(也许是特殊内容/ MIME 类型?或者是 gzip 内容编码?)

"response": { "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "cookies": [], "headers": [{ "name": "Cache-Control", "value": "max-age=0, no-cache, no-store" }, { "name": "Content-Encoding", "value": "gzip" }, { "name": "Content-Type", "value": "application/some.custom.type-v1+json" }, { "name": "Date", "value": "Thu, 15 Feb 2018 13:07:39 GMT" }, { "name": "Pragma", "value": "no-cache" }, { "name": "Render-Time", "value": "92" }, { "name": "Server", "value": "openresty" }, { "name": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains" }, { "name": "Vary", "value": "Accept-Encoding" }, { "name": "Content-Length", "value": "1978" }, { "name": "Connection", "value": "keep-alive" }], "content": { "size": 7429, "mimeType": "application/some.custom.type-v1+json", "comment": "" < 这里没有别的了!! > }, "redirectURL": "", "headersSize": 444, "bodySize": 1978, "comment": "" }, ...

哦对了,两个请求都是使用 MITM 的 HTTPS。

点赞
用户1591921
用户1591921

我认为我找到了自己问题的答案

在 BrowserMobHttpClient.java,我找到了以下内容:

private boolean hasTextualContent(String contentType) {
    return contentType != null && contentType.startsWith("text/") ||
            contentType.startsWith("application/x-javascript") ||
            contentType.startsWith("application/javascript")  ||
            contentType.startsWith("application/json")  ||
            contentType.startsWith("application/xml")  ||
            contentType.startsWith("application/xhtml+xml");
}

看起来我需要制作一个定制版的browsermob-proxy才能让它工作。

2018-02-15 16:27:51