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

Issue: SPR-15212
This commit is contained in:
Juergen Hoeller 2017-02-02 20:01:10 +01:00
parent e44533f4c2
commit 9b3131ffba
1 changed files with 5 additions and 5 deletions

View File

@ -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);