mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
240 stars 54 forks source link

Bad chunked encoded request fail #52

Closed jecuendet closed 6 years ago

jecuendet commented 6 years ago

We have an IIS server which respond a bad encoded chunked response (PDF data) This server is proxified by Apache 2.4 and it works, if we get the PDF directly from the server (No RP), it works.

Charon fail at returning the data because the chunked response is not right according to the specification: https://en.wikipedia.org/wiki/Chunked_transfer_encoding

The chunked response should end with an empty chunked (len=0), but our server doesn't do that. It send the real data in chunked (in fact only one BIG chunk) ans then ends the HTTP stream

We have made a change in Charon to support this, as a workaround. It can be found in the attached PR

What do you think?

jecuendet commented 6 years ago

PR https://github.com/mkopylec/charon-spring-boot-starter/pull/53

mkopylec commented 6 years ago

I would like to keep Charon "clean" and not support use cases that are generally not right according to specifications. Charon's API is intentionally public and divided into many Spring beans, to provide an easy way to deal with workarounds. IMO the solution for your problem is quite simple. Just create a Spring bean based on your pull request:

@Component
public class CustomHttpClientProvider extends HttpClientProvider {

     protected RestOperations createHttpClient(MappingProperties mapping) {
         final RestTemplate rt = super.createHttpClient(mapping);

         /**
          * Creates converters according workarounds
          */
         final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
         if (mapping.getWorkarounds().isPrematureEndOfChunk()) {
             messageConverters.add(new PrematureEndOfChunkHttpMessageConverter());
         }
         else {
             messageConverters.add(new ByteArrayHttpMessageConverter());
         }
         rt.setMessageConverters(messageConverters);
         return rt;
     }
 }

Is this OK for you?

jecuendet commented 6 years ago

Yes it is! But I still need the #54 PR to add metadata right?

mkopylec commented 6 years ago

Ah, OK. Now I see the point of adding metadata to MappingProperties :)

mkopylec commented 6 years ago

Released in 2.5.0 with minor changes. See: https://github.com/mkopylec/charon-spring-boot-starter#custom-mapping-properties