|
12 | 12 |
|
13 | 13 | package org.kpax.winfoom.proxy;
|
14 | 14 |
|
| 15 | +import org.apache.commons.lang3.StringUtils; |
15 | 16 | import org.apache.commons.lang3.tuple.Pair;
|
16 | 17 | import org.apache.http.*;
|
17 | 18 | import org.apache.http.client.ClientProtocolException;
|
18 | 19 | import org.apache.http.client.methods.CloseableHttpResponse;
|
| 20 | +import org.apache.http.config.MessageConstraints; |
19 | 21 | import org.apache.http.impl.client.CloseableHttpClient;
|
20 | 22 | import org.apache.http.impl.client.HttpClientBuilder;
|
21 | 23 | import org.apache.http.impl.execchain.TunnelRefusedException;
|
|
28 | 30 | import org.kpax.winfoom.config.UserConfig;
|
29 | 31 | import org.kpax.winfoom.util.HttpUtils;
|
30 | 32 | import org.kpax.winfoom.util.LocalIOUtils;
|
| 33 | +import org.kpax.winfoom.util.ObjectFormat; |
31 | 34 | import org.slf4j.Logger;
|
32 | 35 | import org.slf4j.LoggerFactory;
|
33 | 36 | import org.springframework.beans.factory.annotation.Autowired;
|
@@ -103,7 +106,11 @@ void handleRequest() {
|
103 | 106 | try {
|
104 | 107 | // Prepare request parsing (this is the client's request)
|
105 | 108 | SessionInputBufferImpl inputBuffer = new SessionInputBufferImpl(
|
106 |
| - new HttpTransportMetricsImpl(), LocalIOUtils.DEFAULT_BUFFER_SIZE); |
| 109 | + new HttpTransportMetricsImpl(), |
| 110 | + LocalIOUtils.DEFAULT_BUFFER_SIZE, |
| 111 | + LocalIOUtils.DEFAULT_BUFFER_SIZE, |
| 112 | + MessageConstraints.DEFAULT, |
| 113 | + ObjectFormat.UTF_8.newDecoder()); |
107 | 114 | inputBuffer.bind(localSocketChannel.getInputStream());
|
108 | 115 |
|
109 | 116 | // Parse the request (all but the message body )
|
@@ -306,8 +313,22 @@ private void handleNonConnectResponse(final CloseableHttpResponse response) {
|
306 | 313 | localSocketChannel.write(response.getStatusLine());
|
307 | 314 |
|
308 | 315 | for (Header header : response.getAllHeaders()) {
|
309 |
| - logger.debug("Write response header: {}", header); |
310 |
| - localSocketChannel.write(header); |
| 316 | + if (HttpHeaders.TRANSFER_ENCODING.equals(header.getName())) { |
| 317 | + // Strip 'chunked' from Transfer-Encoding header's value |
| 318 | + // since the response is not chunked |
| 319 | + String nonChunkedTransferEncoding = HttpUtils.stripChunked(header.getValue()); |
| 320 | + if (StringUtils.isNotEmpty(nonChunkedTransferEncoding)) { |
| 321 | + localSocketChannel.write( |
| 322 | + HttpUtils.createHttpHeader(HttpHeaders.TRANSFER_ENCODING, |
| 323 | + nonChunkedTransferEncoding)); |
| 324 | + logger.debug("Add chunk-striped header response"); |
| 325 | + } else { |
| 326 | + logger.debug("Remove transfer encoding chunked header response"); |
| 327 | + } |
| 328 | + } else { |
| 329 | + logger.debug("Write response header: {}", header); |
| 330 | + localSocketChannel.write(header); |
| 331 | + } |
311 | 332 | }
|
312 | 333 |
|
313 | 334 | // Empty line marking the end
|
|
0 commit comments