Skip to content

Commit 9794fe8

Browse files
committed
Merge pull request webmetrics#63 from jeffriejoshua/master
Modified to log the request body during post
2 parents 30a8978 + 4801af7 commit 9794fe8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/java/net/lightbody/bmp/core/har/HarRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class HarRequest {
1616
private HarPostData postData;
1717
private long headersSize; // Odd grammar in spec
1818
private long bodySize;
19+
private String requestBody;
1920
private String comment = "";
2021

2122
public HarRequest() {
@@ -106,4 +107,13 @@ public String getComment() {
106107
public void setComment(String comment) {
107108
this.comment = comment;
108109
}
110+
111+
public String getRequestBody() {
112+
return requestBody;
113+
}
114+
115+
public void setRequestBody(String requestBody) {
116+
this.requestBody = requestBody;
117+
}
118+
109119
}

src/main/java/net/lightbody/bmp/proxy/http/BrowserMobHttpClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.sf.uadetector.ReadableUserAgent;
66
import net.sf.uadetector.UserAgentStringParser;
77
import net.sf.uadetector.service.UADetectorServiceFactory;
8+
89
import org.apache.http.*;
910
import org.apache.http.auth.*;
1011
import org.apache.http.client.CredentialsProvider;
@@ -36,6 +37,7 @@
3637
import org.apache.http.protocol.ExecutionContext;
3738
import org.apache.http.protocol.HttpContext;
3839
import org.apache.http.protocol.HttpRequestExecutor;
40+
import org.apache.http.util.EntityUtils;
3941
import org.eclipse.jetty.util.MultiMap;
4042
import org.eclipse.jetty.util.UrlEncoded;
4143
import org.java_bandwidthlimiter.StreamManager;
@@ -142,17 +144,26 @@ protected HttpRequestExecutor createRequestExecutor() {
142144
protected HttpResponse doSendRequest(HttpRequest request, HttpClientConnection conn, HttpContext context) throws IOException, HttpException {
143145
long requestHeadersSize = request.getRequestLine().toString().length() + 4;
144146
long requestBodySize = 0;
147+
String requestBody = null;
145148
for (Header header : request.getAllHeaders()) {
146149
requestHeadersSize += header.toString().length() + 2;
147150
if (header.getName().equals("Content-Length")) {
148151
requestBodySize += Integer.valueOf(header.getValue());
149152
}
150153
}
154+
155+
if(request instanceof HttpEntityEnclosingRequest){
156+
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
157+
if (entity != null && entity.getContentLength() > 0) {
158+
requestBody = EntityUtils.toString(entity, "UTF-8");
159+
}
160+
}
151161

152162
HarEntry entry = RequestInfo.get().getEntry();
153163
if (entry != null) {
154164
entry.getRequest().setHeadersSize(requestHeadersSize);
155165
entry.getRequest().setBodySize(requestBodySize);
166+
entry.getRequest().setRequestBody(requestBody);
156167
}
157168

158169
Date start = new Date();

0 commit comments

Comments
 (0)