@@ -19,6 +19,8 @@ public class RequestInfo {
1919
2020 public String body ;
2121
22+ public String contentType ;
23+
2224 public RequestInfo (
2325 String method , String url , Map <String , String > queryParams , Map <String , String > headers ) {
2426 this .method = method ;
@@ -33,6 +35,7 @@ protected RequestInfo(Builder builder) {
3335 this .queryParams = builder .queryParams ;
3436 this .headers = builder .headers ;
3537 this .body = builder .body ;
38+ this .contentType = builder .contentType ;
3639 }
3740
3841 public String getMethod () {
@@ -55,6 +58,10 @@ public String getBody() {
5558 return body ;
5659 }
5760
61+ public String getContentType () {
62+ return contentType ;
63+ }
64+
5865 public static class Builder {
5966
6067 protected final String method ;
@@ -67,6 +74,8 @@ public static class Builder {
6774
6875 protected String body ;
6976
77+ protected String contentType ;
78+
7079 public Builder (
7180 String method , String url , Map <String , String > queryParams , Map <String , String > headers ) {
7281 this .method = method ;
@@ -80,12 +89,21 @@ public Builder body(String body) {
8089 return this ;
8190 }
8291
92+ public Builder contentType (String contentType ) {
93+ this .contentType = contentType ;
94+ return this ;
95+ }
96+
8397 public RequestInfo build () {
8498 return new RequestInfo (this );
8599 }
86100 }
87101
88102 public static RequestInfo fromRequest (Request request ) {
103+ return fromRequest (request , null );
104+ }
105+
106+ public static RequestInfo fromRequest (Request request , String contentType ) {
89107 Builder requestInfoBuilder =
90108 new Builder (
91109 request .method (),
@@ -95,7 +113,8 @@ public static RequestInfo fromRequest(Request request) {
95113 Collectors .toMap (name -> name , name -> request .url ().queryParameter (name ))),
96114 request .headers ().toMultimap ().entrySet ().stream ()
97115 .collect (Collectors .toMap (Map .Entry ::getKey , e -> e .getValue ().get (0 ))))
98- .body (getRequestBodyAsString (request .body ()));
116+ .body (getRequestBodyAsString (request .body ()))
117+ .contentType (contentType );
99118
100119 return new RequestInfo (requestInfoBuilder );
101120 }
@@ -116,6 +135,12 @@ private static String getRequestBodyAsString(RequestBody requestBody) {
116135 String print (DataSanitizer dataSanitizer ) {
117136 Map <String , String > sanitizedHeaders =
118137 dataSanitizer == null ? headers : dataSanitizer .sanitizeHeaders (headers );
138+ String sanitizedBody ;
139+ if (dataSanitizer == null || body == null ) {
140+ sanitizedBody = body ;
141+ } else {
142+ sanitizedBody = dataSanitizer .sanitizeStringBody (body , contentType );
143+ }
119144 return "RequestInfo{"
120145 + "\n \t method='"
121146 + method
@@ -128,7 +153,7 @@ String print(DataSanitizer dataSanitizer) {
128153 + ", \n \t headers="
129154 + sanitizedHeaders
130155 + ", \n \t body='"
131- + body
156+ + sanitizedBody
132157 + '\''
133158 + '}' ;
134159 }
0 commit comments