Skip to content

Commit

Permalink
Merge pull request webmetrics#63 from jeffriejoshua/master
Browse files Browse the repository at this point in the history
Modified to log the request body during post
  • Loading branch information
lightbody committed Mar 24, 2014
2 parents 30a8978 + 4801af7 commit 9794fe8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/net/lightbody/bmp/core/har/HarRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class HarRequest {
private HarPostData postData;
private long headersSize; // Odd grammar in spec
private long bodySize;
private String requestBody;
private String comment = "";

public HarRequest() {
Expand Down Expand Up @@ -106,4 +107,13 @@ public String getComment() {
public void setComment(String comment) {
this.comment = comment;
}

public String getRequestBody() {
return requestBody;
}

public void setRequestBody(String requestBody) {
this.requestBody = requestBody;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.sf.uadetector.ReadableUserAgent;
import net.sf.uadetector.UserAgentStringParser;
import net.sf.uadetector.service.UADetectorServiceFactory;

import org.apache.http.*;
import org.apache.http.auth.*;
import org.apache.http.client.CredentialsProvider;
Expand Down Expand Up @@ -36,6 +37,7 @@
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.util.EntityUtils;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.UrlEncoded;
import org.java_bandwidthlimiter.StreamManager;
Expand Down Expand Up @@ -142,17 +144,26 @@ protected HttpRequestExecutor createRequestExecutor() {
protected HttpResponse doSendRequest(HttpRequest request, HttpClientConnection conn, HttpContext context) throws IOException, HttpException {
long requestHeadersSize = request.getRequestLine().toString().length() + 4;
long requestBodySize = 0;
String requestBody = null;
for (Header header : request.getAllHeaders()) {
requestHeadersSize += header.toString().length() + 2;
if (header.getName().equals("Content-Length")) {
requestBodySize += Integer.valueOf(header.getValue());
}
}

if(request instanceof HttpEntityEnclosingRequest){
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity != null && entity.getContentLength() > 0) {
requestBody = EntityUtils.toString(entity, "UTF-8");
}
}

HarEntry entry = RequestInfo.get().getEntry();
if (entry != null) {
entry.getRequest().setHeadersSize(requestHeadersSize);
entry.getRequest().setBodySize(requestBodySize);
entry.getRequest().setRequestBody(requestBody);
}

Date start = new Date();
Expand Down

0 comments on commit 9794fe8

Please sign in to comment.