net.lightbody.bmp.util.BrowserMobHttpUtil Java Examples
The following examples show how to use
net.lightbody.bmp.util.BrowserMobHttpUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpsHostCaptureFilter.java From CapturePacket with MIT License | 6 votes |
@Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) httpObject; if (ProxyUtils.isCONNECT(httpRequest)) { Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME)); String hostAndPort = httpRequest.getUri(); // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example) // would be unexpected. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443); hostname.set(hostNoDefaultPort); } } return null; }
Example #2
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 6 votes |
protected void captureResponse(HttpResponse httpResponse) { HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text()); harEntry.setResponse(response); captureResponseHeaderSize(httpResponse); captureResponseMimeType(httpResponse); if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) { captureResponseCookies(httpResponse); } if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) { captureResponseHeaders(httpResponse); } if (BrowserMobHttpUtil.isRedirect(httpResponse)) { captureRedirectUrl(httpResponse); } }
Example #3
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 6 votes |
protected void captureResponse(HttpResponse httpResponse) { HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text()); harEntry.setResponse(response); captureResponseHeaderSize(httpResponse); captureResponseMimeType(httpResponse); if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) { captureResponseCookies(httpResponse); } if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) { captureResponseHeaders(httpResponse); } if (BrowserMobHttpUtil.isRedirect(httpResponse)) { captureRedirectUrl(httpResponse); } }
Example #4
Source File: HttpsHostCaptureFilter.java From AndroidHttpCapture with MIT License | 6 votes |
@Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) httpObject; if (ProxyUtils.isCONNECT(httpRequest)) { Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME)); String hostAndPort = httpRequest.getUri(); // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example) // would be unexpected. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443); hostname.set(hostNoDefaultPort); } } return null; }
Example #5
Source File: HttpsHostCaptureFilter.java From Dream-Catcher with MIT License | 6 votes |
@Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) httpObject; if (ProxyUtils.isCONNECT(httpRequest)) { Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME)); String hostAndPort = httpRequest.getUri(); // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example) // would be unexpected. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443); hostname.set(hostNoDefaultPort); } } return null; }
Example #6
Source File: HarCaptureFilter.java From Dream-Catcher with MIT License | 6 votes |
protected void captureResponse(HttpResponse httpResponse) { Log.e("InnerHandle", "captureResponse " + harEntry.getId()); HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text()); harEntry.setResponse(response); captureResponseHeaderSize(httpResponse); captureResponseMimeType(httpResponse); if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) { captureResponseCookies(httpResponse); } if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) { captureResponseHeaders(httpResponse); } if (BrowserMobHttpUtil.isRedirect(httpResponse)) { captureRedirectUrl(httpResponse); } }
Example #7
Source File: HarCaptureFilter.java From Dream-Catcher with MIT License | 5 votes |
protected void captureRequestHeaderSize(HttpRequest httpRequest) { Log.e("InnerHandle", "captureRequestHeaderSize " + harEntry.getId()); String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString(); // +2 => CRLF after status line, +4 => header/data separation long requestHeadersSize = requestLine.length() + 6; HttpHeaders headers = httpRequest.headers(); requestHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harRequest.getRequest().setHeadersSize(requestHeadersSize); }
Example #8
Source File: ServerResponseCaptureFilter.java From AndroidHttpCapture with MIT License | 5 votes |
protected void decompressContents() { if (contentEncoding.equalsIgnoreCase(HttpHeaders.Values.GZIP) || contentEncoding.equalsIgnoreCase(HttpHeaders.Values.DEFLATE)) { try { fullResponseContents = BrowserMobHttpUtil.decompressContents(getRawResponseContents(),contentEncoding); decompressionSuccessful = true; } catch (RuntimeException e) { log.warn("Failed to decompress response with encoding type " + contentEncoding + " when decoding request from " + originalRequest.getUri(), e); } } else{ log.warn("Cannot decode unsupported content encoding type {}", contentEncoding); } }
Example #9
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 5 votes |
protected void captureResponseHeaderSize(HttpResponse httpResponse) { String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString(); // +2 => CRLF after status line, +4 => header/data separation long responseHeadersSize = statusLine.length() + 6; HttpHeaders headers = httpResponse.headers(); responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harEntry.getResponse().setHeadersSize(responseHeadersSize); }
Example #10
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 5 votes |
protected void captureResponseContent(HttpResponse httpResponse, byte[] fullMessage) { // force binary if the content encoding is not supported boolean forceBinary = false; String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in response from {}. Content will be treated as {}", originalRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } if (responseCaptureFilter.isResponseCompressed() && !responseCaptureFilter.isDecompressionSuccessful()) { log.warn("Unable to decompress content with encoding: {}. Contents will be encoded as base64 binary data.", responseCaptureFilter.getContentEncoding()); forceBinary = true; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP response from {}. Content will not be captured in HAR.", contentType, originalRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents from {}", charset, originalRequest.getUri()); } if (!forceBinary && BrowserMobHttpUtil.hasTextualContent(contentType)) { String text = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getResponse().getContent().setText(text); } else if (dataToCapture.contains(CaptureType.RESPONSE_BINARY_CONTENT)) { harEntry.getResponse().getContent().setText(BaseEncoding.base64().encode(fullMessage)); harEntry.getResponse().getContent().setEncoding("base64"); } harEntry.getResponse().getContent().setSize(fullMessage.length); }
Example #11
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 5 votes |
protected void captureRequestHeaderSize(HttpRequest httpRequest) { String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString(); // +2 => CRLF after status line, +4 => header/data separation long requestHeadersSize = requestLine.length() + 6; HttpHeaders headers = httpRequest.headers(); requestHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harEntry.getRequest().setHeadersSize(requestHeadersSize); }
Example #12
Source File: HttpsAwareFiltersAdapter.java From AndroidHttpCapture with MIT License | 5 votes |
/** * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect * modifications from this or other filters. This filter instance must be currently handling the specified request; * otherwise the results are undefined. * * @param modifiedRequest a possibly-modified version of the request currently being processed * @return the full URL of the request, including scheme, host, port, path, and query parameters */ public String getFullUrl(HttpRequest modifiedRequest) { // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request if (ProxyUtils.isCONNECT(modifiedRequest)) { // CONNECT requests contain the default port, even if it isn't specified on the request. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443); return "https://" + hostNoDefaultPort; } // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request. // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly. if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri(); } // The URI did not include the scheme and host, so examine the request to obtain them: // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps() // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method. // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI // contains only the path and query params. String hostAndPort = getHostAndPort(modifiedRequest); String path = modifiedRequest.getUri(); String url; if (isHttps()) { url = "https://" + hostAndPort + path; } else { url = "http://" + hostAndPort + path; } return url; }
Example #13
Source File: BrowserMobProxyServer.java From AndroidHttpCapture with MIT License | 5 votes |
@Override public void chainedProxyAuthorization(String username, String password, AuthType authType) { switch (authType) { case BASIC: chainedProxyCredentials = BrowserMobHttpUtil.base64EncodeBasicCredentials(username, password); break; default: throw new UnsupportedOperationException("AuthType " + authType + " is not supported for Proxy Authorization"); } }
Example #14
Source File: BrowserMobProxyServer.java From AndroidHttpCapture with MIT License | 5 votes |
@Override public void autoAuthorization(String domain, String username, String password, AuthType authType) { switch (authType) { case BASIC: // base64 encode the "username:password" string String base64EncodedCredentials = BrowserMobHttpUtil.base64EncodeBasicCredentials(username, password); basicAuthCredentials.put(domain, base64EncodedCredentials); break; default: throw new UnsupportedOperationException("AuthType " + authType + " is not supported for HTTP Authorization"); } }
Example #15
Source File: ServerResponseCaptureFilter.java From Dream-Catcher with MIT License | 5 votes |
protected void decompressContents() { if (contentEncoding.equals(HttpHeaders.Values.GZIP)) { try { fullResponseContents = BrowserMobHttpUtil.decompressContents(getRawResponseContents()); decompressionSuccessful = true; } catch (RuntimeException e) { log.warn("Failed to decompress response with encoding type " + contentEncoding + " when decoding request from " + originalRequest.getUri(), e); } } else { log.warn("Cannot decode unsupported content encoding type {}", contentEncoding); } }
Example #16
Source File: HarCaptureFilter.java From Dream-Catcher with MIT License | 5 votes |
protected void captureResponseHeaderSize(HttpResponse httpResponse) { Log.e("InnerHandle", "captureResponseHeaderSize " + harEntry.getId()); String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString(); // +2 => CRLF after status line, +4 => header/data separation long responseHeadersSize = statusLine.length() + 6; HttpHeaders headers = httpResponse.headers(); responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harResponse.getResponse().setHeadersSize(responseHeadersSize); }
Example #17
Source File: BrowserMobProxyServer.java From CapturePacket with MIT License | 5 votes |
@Override public void autoAuthorization(String domain, String username, String password, AuthType authType) { switch (authType) { case BASIC: // base64 encode the "username:password" string String base64EncodedCredentials = BrowserMobHttpUtil.base64EncodeBasicCredentials(username, password); basicAuthCredentials.put(domain, base64EncodedCredentials); break; default: throw new UnsupportedOperationException("AuthType " + authType + " is not supported for HTTP Authorization"); } }
Example #18
Source File: HttpsAwareFiltersAdapter.java From Dream-Catcher with MIT License | 5 votes |
/** * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect * modifications from this or other filters. This filter instance must be currently handling the specified request; * otherwise the results are undefined. * * @param modifiedRequest a possibly-modified version of the request currently being processed * @return the full URL of the request, including scheme, host, port, path, and query parameters */ public String getFullUrl(HttpRequest modifiedRequest) { // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request if (ProxyUtils.isCONNECT(modifiedRequest)) { // CONNECT requests contain the default port, even if it isn't specified on the request. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443); return "https://" + hostNoDefaultPort; } // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request. // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly. if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri(); } // The URI did not include the scheme and host, so examine the request to obtain them: // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps() // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method. // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI // contains only the path and query params. String hostAndPort = getHostAndPort(modifiedRequest); String path = modifiedRequest.getUri(); String url; if (isHttps()) { url = "https://" + hostAndPort + path; } else { url = "http://" + hostAndPort + path; } return url; }
Example #19
Source File: BrowserMobProxyServer.java From Dream-Catcher with MIT License | 5 votes |
@Override public void chainedProxyAuthorization(String username, String password, AuthType authType) { switch (authType) { case BASIC: chainedProxyCredentials = BrowserMobHttpUtil.base64EncodeBasicCredentials(username, password); break; default: throw new UnsupportedOperationException("AuthType " + authType + " is not supported for Proxy Authorization"); } }
Example #20
Source File: BrowserMobProxyServer.java From Dream-Catcher with MIT License | 5 votes |
@Override public void autoAuthorization(String domain, String username, String password, AuthType authType) { switch (authType) { case BASIC: // base64 encode the "username:password" string String base64EncodedCredentials = BrowserMobHttpUtil.base64EncodeBasicCredentials(username, password); basicAuthCredentials.put(domain, base64EncodedCredentials); break; default: throw new UnsupportedOperationException("AuthType " + authType + " is not supported for HTTP Authorization"); } }
Example #21
Source File: ServerResponseCaptureFilter.java From CapturePacket with MIT License | 5 votes |
protected void decompressContents() { if (contentEncoding.equalsIgnoreCase(HttpHeaders.Values.GZIP) || contentEncoding.equalsIgnoreCase(HttpHeaders.Values.DEFLATE)) { try { fullResponseContents = BrowserMobHttpUtil.decompressContents(getRawResponseContents(),contentEncoding); decompressionSuccessful = true; } catch (RuntimeException e) { log.warn("Failed to decompress response with encoding type " + contentEncoding + " when decoding request from " + originalRequest.getUri(), e); } } else{ log.warn("Cannot decode unsupported content encoding type {}", contentEncoding); } }
Example #22
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 5 votes |
protected void captureResponseHeaderSize(HttpResponse httpResponse) { String statusLine = httpResponse.getProtocolVersion().toString() + ' ' + httpResponse.getStatus().toString(); // +2 => CRLF after status line, +4 => header/data separation long responseHeadersSize = statusLine.length() + 6; HttpHeaders headers = httpResponse.headers(); responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harEntry.getResponse().setHeadersSize(responseHeadersSize); }
Example #23
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 5 votes |
protected void captureResponseContent(HttpResponse httpResponse, byte[] fullMessage) { // force binary if the content encoding is not supported boolean forceBinary = false; String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in response from {}. Content will be treated as {}", originalRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } if (responseCaptureFilter.isResponseCompressed() && !responseCaptureFilter.isDecompressionSuccessful()) { log.warn("Unable to decompress content with encoding: {}. Contents will be encoded as base64 binary data.", responseCaptureFilter.getContentEncoding()); forceBinary = true; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP response from {}. Content will not be captured in HAR.", contentType, originalRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents from {}", charset, originalRequest.getUri()); } if (!forceBinary && BrowserMobHttpUtil.hasTextualContent(contentType)) { String text = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getResponse().getContent().setText(text); } else if (dataToCapture.contains(CaptureType.RESPONSE_BINARY_CONTENT)) { harEntry.getResponse().getContent().setText(BaseEncoding.base64().encode(fullMessage)); harEntry.getResponse().getContent().setEncoding("base64"); } harEntry.getResponse().getContent().setSize(fullMessage.length); }
Example #24
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 5 votes |
protected void captureRequestHeaderSize(HttpRequest httpRequest) { String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString(); // +2 => CRLF after status line, +4 => header/data separation long requestHeadersSize = requestLine.length() + 6; HttpHeaders headers = httpRequest.headers(); requestHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harEntry.getRequest().setHeadersSize(requestHeadersSize); }
Example #25
Source File: HttpsAwareFiltersAdapter.java From CapturePacket with MIT License | 5 votes |
/** * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect * modifications from this or other filters. This filter instance must be currently handling the specified request; * otherwise the results are undefined. * * @param modifiedRequest a possibly-modified version of the request currently being processed * @return the full URL of the request, including scheme, host, port, path, and query parameters */ public String getFullUrl(HttpRequest modifiedRequest) { // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request if (ProxyUtils.isCONNECT(modifiedRequest)) { // CONNECT requests contain the default port, even if it isn't specified on the request. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443); return "https://" + hostNoDefaultPort; } // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request. // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly. if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) { return modifiedRequest.getUri(); } // The URI did not include the scheme and host, so examine the request to obtain them: // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps() // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method. // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI // contains only the path and query params. String hostAndPort = getHostAndPort(modifiedRequest); String path = modifiedRequest.getUri(); String url; if (isHttps()) { url = "https://" + hostAndPort + path; } else { url = "http://" + hostAndPort + path; } return url; }
Example #26
Source File: BrowserMobProxyServer.java From CapturePacket with MIT License | 5 votes |
@Override public void chainedProxyAuthorization(String username, String password, AuthType authType) { switch (authType) { case BASIC: chainedProxyCredentials = BrowserMobHttpUtil.base64EncodeBasicCredentials(username, password); break; default: throw new UnsupportedOperationException("AuthType " + authType + " is not supported for Proxy Authorization"); } }
Example #27
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 4 votes |
protected void captureRequestContent(HttpRequest httpRequest, byte[] fullMessage) { if (fullMessage.length == 0) { return; } String contentType = HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in request to {}. Content will be treated as {}", httpRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } HarPostData postData = new HarPostData(); harEntry.getRequest().setPostData(postData); postData.setMimeType(contentType); boolean urlEncoded; if (contentType.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED)) { urlEncoded = true; } else { urlEncoded = false; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP request to {}. Content will not be captured in HAR.", contentType, httpRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents to {}", charset, httpRequest.getUri()); } if (urlEncoded) { String textContents = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(textContents, charset, false); ImmutableList.Builder<HarPostDataParam> paramBuilder = ImmutableList.builder(); for (Map.Entry<String, List<String>> entry : queryStringDecoder.parameters().entrySet()) { for (String value : entry.getValue()) { paramBuilder.add(new HarPostDataParam(entry.getKey(), value)); } } harEntry.getRequest().getPostData().setParams(paramBuilder.build()); } else { //TODO: implement capture of files and multipart form data // not URL encoded, so let's grab the body of the POST and capture that String postBody = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getRequest().getPostData().setText(postBody); } }
Example #28
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 4 votes |
protected void captureRequestContent(HttpRequest httpRequest, byte[] fullMessage) { if (fullMessage.length == 0) { return; } String contentType = HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in request to {}. Content will be treated as {}", httpRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } HarPostData postData = new HarPostData(); harEntry.getRequest().setPostData(postData); postData.setMimeType(contentType); boolean urlEncoded; if (contentType.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED)) { urlEncoded = true; } else { urlEncoded = false; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP request to {}. Content will not be captured in HAR.", contentType, httpRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents to {}", charset, httpRequest.getUri()); } if (urlEncoded) { String textContents = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(textContents, charset, false); ImmutableList.Builder<HarPostDataParam> paramBuilder = ImmutableList.builder(); for (Map.Entry<String, List<String>> entry : queryStringDecoder.parameters().entrySet()) { for (String value : entry.getValue()) { paramBuilder.add(new HarPostDataParam(entry.getKey(), value)); } } harEntry.getRequest().getPostData().setParams(paramBuilder.build()); } else { //TODO: implement capture of files and multipart form data // not URL encoded, so let's grab the body of the POST and capture that String postBody = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getRequest().getPostData().setText(postBody); } }