From e9adabe4d28b120d0ccbbcd7080cd8a472628619 Mon Sep 17 00:00:00 2001 From: Archish Thakkar Date: Wed, 24 Mar 2021 10:40:27 +0530 Subject: [PATCH] :sparkle: Added request param as captureRequestContent in HAR --- README.md | 2 +- .../bup/proxy/bricks/ProxyResource.java | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b3fcb3330..fb1617720 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Description | HTTP method | Request path | Request parameters --- | :---: | :---: | --- Get a list of ports attached to `ProxyServer` instances managed by `ProxyManager` | GET | */proxy* || Creates a new proxy to run requests off of | POST | */proxy* |

*port* - Integer, The specific port to start the proxy service on. Optional, default is generated and returned in response.

*proxyUsername* - String, The username to use to authenticate with the chained proxy. Optional, default to null.

*proxyPassword* - String, The password to use to authenticate with the chained proxy. Optional, default to null.

*bindAddress* - String, If running BrowserUp Proxy in a multi-homed environment, specify a desired bind address. Optional, default to "0.0.0.0".

*serverBindAddress* - String, If running BrowserUp Proxy in a multi-homed environment, specify a desired server bind address. Optional, default to "0.0.0.0".

*useEcc* - Boolean. True, Uses Elliptic Curve Cryptography for certificate impersonation. Optional, default to "false".

*trustAllServers* - Boolean. True, Disables verification of all upstream servers' SSL certificates. All upstream servers will be trusted, even if they do not present valid certificates signed by certification authorities in the JDK's trust store. Optional, default to "false".

| -Creates a new HAR attached to the proxy and returns the HAR content if there was a previous HAR. *[port]* in request path it is port where your proxy was started | PUT |*/proxy/[port]/har* |

*captureHeaders* - Boolean, capture headers or not. Optional, default to "false".

*captureCookies* - Boolean, capture cookies or not. Optional, default to "false".

*captureContent* - Boolean, capture content bodies or not. Optional, default to "false".

*captureBinaryContent* - Boolean, capture binary content or not. Optional, default to "false".

*initialPageRef* - The string name of The first page ref that should be used in the HAR. Optional, default to "Page 1".

*initialPageTitle* - The title of first HAR page. Optional, default to *initialPageRef*.

+Creates a new HAR attached to the proxy and returns the HAR content if there was a previous HAR. *[port]* in request path it is port where your proxy was started | PUT |*/proxy/[port]/har* |

*captureHeaders* - Boolean, capture headers or not. Optional, default to "false".

*captureCookies* - Boolean, capture cookies or not. Optional, default to "false".

*captureRequestContent* - Boolean, capture only request content body or not. Optional, default to "false".

*captureContent* - Boolean, capture content bodies or not. Optional, default to "false".

*captureBinaryContent* - Boolean, capture binary content or not. Optional, default to "false".

*initialPageRef* - The string name of The first page ref that should be used in the HAR. Optional, default to "Page 1".

*initialPageTitle* - The title of first HAR page. Optional, default to *initialPageRef*.

Starts a new page on the existing HAR. *[port]* in request path it is port where your proxy was started | PUT | */proxy/[port]/har/pageRef* |

*pageRef* - The string name of the first page ref that should be used in the HAR. Optional, default to "Page N" where N is the next page number.

*pageTitle* - The title of new HAR page. Optional, default to `pageRef`.

Shuts down the proxy and closes the port. *[port]* in request path it is port where your proxy was started | DELETE | */proxy/[port]* || Returns the JSON/HAR content representing all the HTTP traffic passed through the proxy (provided you have already created the HAR with [this method](#harcreate)) | GET | */proxy/[port]/har* || diff --git a/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/bricks/ProxyResource.java b/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/bricks/ProxyResource.java index 7c66db2e9..a01bd44ed 100644 --- a/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/bricks/ProxyResource.java +++ b/browserup-proxy-rest/src/main/java/com/browserup/bup/proxy/bricks/ProxyResource.java @@ -163,22 +163,26 @@ public Reply getHar(@Named("port") int port, Request request) { public Reply newHar(@Named("port") int port, Request request) { LOG.info("PUT /" + port + "/har"); LOG.info(request.params().toString()); - MitmProxyServer proxy = proxyManager.get(port); + final MitmProxyServer proxy = proxyManager.get(port); if (proxy == null) { return Reply.saying().notFound(); } - String initialPageRef = request.param("initialPageRef"); - String initialPageTitle = request.param("initialPageTitle"); - Har oldHar = proxy.newHar(initialPageRef, initialPageTitle); + final String initialPageRef = request.param("initialPageRef"); + final String initialPageTitle = request.param("initialPageTitle"); + final Har oldHar = proxy.newHar(initialPageRef, initialPageTitle); - String captureHeaders = request.param("captureHeaders"); - String captureContent = request.param("captureContent"); - String captureBinaryContent = request.param("captureBinaryContent"); - Set captureTypes = new HashSet(); + final String captureHeaders = request.param("captureHeaders"); + final String captureRequestContent = request.param("captureRequestContent"); + final String captureContent = request.param("captureContent"); + final String captureBinaryContent = request.param("captureBinaryContent"); + final Set captureTypes = new HashSet(); if (Boolean.parseBoolean(captureHeaders)) { captureTypes.addAll(CaptureType.getHeaderCaptureTypes()); } + if(Boolean.parseBoolean(captureRequestContent)){ + captureTypes.addAll(CaptureType.getRequestCaptureTypes()); + } if (Boolean.parseBoolean(captureContent)) { captureTypes.addAll(CaptureType.getAllContentCaptureTypes()); } @@ -187,9 +191,9 @@ public Reply newHar(@Named("port") int port, Request request) { } proxy.setHarCaptureTypes(captureTypes); - String captureCookies = request.param("captureCookies"); + final String captureCookies = request.param("captureCookies"); if (proxy instanceof MitmProxyServer && Boolean.parseBoolean(captureCookies)) { - MitmProxyServer MitmProxyServer = (MitmProxyServer) proxy; + final MitmProxyServer MitmProxyServer = (MitmProxyServer) proxy; MitmProxyServer.enableHarCaptureTypes(CaptureType.getCookieCaptureTypes()); }