Browse Source

Skip default Content-Length if Transfer-Encoding header has been set

Issue: SPR-15212
pull/1312/head
Juergen Hoeller 9 years ago
parent
commit
9b3131ffba
  1. 10
      spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java

10
spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -96,7 +96,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
* Set the list of {@link MediaType} objects supported by this converter. * Set the list of {@link MediaType} objects supported by this converter.
*/ */
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) { public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) {
Assert.notEmpty(supportedMediaTypes, "'supportedMediaTypes' must not be empty"); Assert.notEmpty(supportedMediaTypes, "MediaType List must not be empty");
this.supportedMediaTypes = new ArrayList<>(supportedMediaTypes); this.supportedMediaTypes = new ArrayList<>(supportedMediaTypes);
} }
@ -231,8 +231,8 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
/** /**
* Add default headers to the output message. * Add default headers to the output message.
* <p>This implementation delegates to {@link #getDefaultContentType(Object)} if a content * <p>This implementation delegates to {@link #getDefaultContentType(Object)} if a
* type was not provided, set if necessary the default character set, calls * content type was not provided, set if necessary the default character set, calls
* {@link #getContentLength}, and sets the corresponding headers. * {@link #getContentLength}, and sets the corresponding headers.
* @since 4.2 * @since 4.2
*/ */
@ -256,7 +256,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
headers.setContentType(contentTypeToUse); headers.setContentType(contentTypeToUse);
} }
} }
if (headers.getContentLength() < 0) { if (headers.getContentLength() < 0 && !headers.containsKey(HttpHeaders.TRANSFER_ENCODING)) {
Long contentLength = getContentLength(t, headers.getContentType()); Long contentLength = getContentLength(t, headers.getContentType());
if (contentLength != null) { if (contentLength != null) {
headers.setContentLength(contentLength); headers.setContentLength(contentLength);

Loading…
Cancel
Save