@@ -127,53 +127,59 @@ public CompletionStage<HttpResponse> apply(final HttpRequest request) {
127
127
.addData ("url" , request .getUri ())
128
128
.addData ("headers" , request .getHeaders ())
129
129
.log ();
130
- return process (request ).whenComplete (
131
- (response , failure ) -> {
132
- requestTimer .stop ();
130
+ return request .entity ().toStrict (30000 , _actorSystem )
131
+ .thenApply (request ::withEntity )
132
+ .thenCompose (strictRequest -> {
133
+ final CompletionStage <HttpResponse > process = this .process (strictRequest );
134
+ process .whenComplete (
135
+ (response , failure ) -> {
136
+ requestTimer .stop ();
133
137
134
- final int responseStatus ;
135
- if (response != null ) {
136
- responseStatus = response .status ().intValue ();
137
- } else {
138
- // TODO(ville): Figure out how to intercept post-exception mapping.
139
- responseStatus = 599 ;
140
- }
138
+ final int responseStatus ;
139
+ if (response != null ) {
140
+ responseStatus = response .status ().intValue ();
141
+ } else {
142
+ // TODO(ville): Figure out how to intercept post-exception mapping.
143
+ responseStatus = 599 ;
144
+ }
141
145
142
- _metrics .recordTimer (
143
- createMetricName (request , responseStatus , REQUEST_METRIC ),
144
- requestTimer .elapsed (TimeUnit .NANOSECONDS ),
145
- Optional .of (TimeUnit .NANOSECONDS ));
146
- _metrics .recordGauge (
147
- createMetricName (request , responseStatus , BODY_SIZE_METRIC ),
148
- request .entity ().getContentLengthOption ().orElse (0L ));
149
- final int responseStatusClass = responseStatus / 100 ;
150
- for (final int i : STATUS_CLASSES ) {
151
- _metrics .recordCounter (
152
- createMetricName (request , responseStatus , String .format ("%s/%dxx" , STATUS_METRIC , i )),
153
- responseStatusClass == i ? 1 : 0 );
154
- }
146
+ _metrics .recordTimer (
147
+ createMetricName (strictRequest , responseStatus , REQUEST_METRIC ),
148
+ requestTimer .elapsed (TimeUnit .NANOSECONDS ),
149
+ Optional .of (TimeUnit .NANOSECONDS ));
150
+ _metrics .recordGauge (
151
+ createMetricName (strictRequest , responseStatus , BODY_SIZE_METRIC ),
152
+ strictRequest .entity ().getContentLengthOption ().orElse (0 ));
153
+ final int responseStatusClass = responseStatus / 100 ;
154
+ for (final int i : STATUS_CLASSES ) {
155
+ _metrics .recordCounter (
156
+ createMetricName (strictRequest , responseStatus , String .format ("%s/%dxx" , STATUS_METRIC , i )),
157
+ responseStatusClass == i ? 1 : 0 );
158
+ }
155
159
156
- final LogBuilder log ;
157
- if (failure != null || responseStatusClass == 5 ) {
158
- log = LOGGER .info ().setEvent ("http.in.failure" );
159
- if (failure != null ) {
160
- log .setThrowable (failure );
161
- }
162
- if (!LOGGER .isTraceEnabled () && LOGGER .isInfoEnabled ()) {
163
- log .addData ("method" , request .method ().toString ())
164
- .addData ("url" , request .getUri ().toString ())
165
- .addData (
166
- "headers" ,
167
- StreamSupport .stream (request .getHeaders ().spliterator (), false )
168
- .map (h -> h .name () + "=" + h .value ())
169
- .collect (Collectors .toList ()));
170
- }
171
- } else {
172
- log = LOGGER .trace ().setEvent ("http.in.complete" );
173
- }
174
- log .addContext ("requestId" , requestId )
175
- .addData ("status" , responseStatus )
176
- .log ();
160
+ final LogBuilder log ;
161
+ if (failure != null || responseStatusClass == 5 ) {
162
+ log = LOGGER .info ().setEvent ("http.in.failure" );
163
+ if (failure != null ) {
164
+ log .setThrowable (failure );
165
+ }
166
+ if (!LOGGER .isTraceEnabled () && LOGGER .isInfoEnabled ()) {
167
+ log .addData ("method" , strictRequest .method ().toString ())
168
+ .addData ("url" , strictRequest .getUri ().toString ())
169
+ .addData (
170
+ "headers" ,
171
+ StreamSupport .stream (strictRequest .getHeaders ().spliterator (), false )
172
+ .map (h -> h .name () + "=" + h .value ())
173
+ .collect (Collectors .toList ()));
174
+ }
175
+ } else {
176
+ log = LOGGER .trace ().setEvent ("http.in.complete" );
177
+ }
178
+ log .addContext ("requestId" , requestId )
179
+ .addData ("status" , responseStatus )
180
+ .log ();
181
+ });
182
+ return process ;
177
183
});
178
184
}
179
185
0 commit comments