From 7f438dc9aa93053b844b4394557039a93fdb805a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Apr 2016 18:44:56 +0200 Subject: [PATCH] Consistent headers.getContentLength() checks --- .../client/AbstractBufferingAsyncClientHttpRequest.java | 4 ++-- .../http/client/AbstractBufferingClientHttpRequest.java | 4 ++-- .../http/converter/AbstractHttpMessageConverter.java | 8 ++++---- .../http/server/ServletServerHttpRequest.java | 2 +- .../java/org/springframework/web/client/RestTemplate.java | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java index cf83983de59..2bcbcdb2989 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ abstract class AbstractBufferingAsyncClientHttpRequest extends AbstractAsyncClie @Override protected ListenableFuture executeInternal(HttpHeaders headers) throws IOException { byte[] bytes = this.bufferedOutput.toByteArray(); - if (headers.getContentLength() == -1) { + if (headers.getContentLength() < 0) { headers.setContentLength(bytes.length); } ListenableFuture result = executeInternal(headers, bytes); diff --git a/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingClientHttpRequest.java index 4af73487984..d468b5877bd 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ abstract class AbstractBufferingClientHttpRequest extends AbstractClientHttpRequ @Override protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException { byte[] bytes = this.bufferedOutput.toByteArray(); - if (headers.getContentLength() == -1) { + if (headers.getContentLength() < 0) { headers.setContentLength(bytes.length); } ClientHttpResponse result = executeInternal(headers, bytes); diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java index 1f1e200882b..42a91192829 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv } /** - * Construct an {@code AbstractHttpMessageConverter} with multiple supported media type. + * Construct an {@code AbstractHttpMessageConverter} with multiple supported media types. * @param supportedMediaTypes the supported media types */ protected AbstractHttpMessageConverter(MediaType... supportedMediaTypes) { @@ -101,7 +101,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv } /** - * Returns true if any of the {@linkplain #setSupportedMediaTypes(List) + * Returns {@code true} if any of the {@linkplain #setSupportedMediaTypes(List) * supported} media types {@link MediaType#includes(MediaType) include} the * given media type. * @param mediaType the media type to read, can be {@code null} if not specified. @@ -217,7 +217,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv headers.setContentType(contentTypeToUse); } } - if (headers.getContentLength() == -1) { + if (headers.getContentLength() < 0) { Long contentLength = getContentLength(t, headers.getContentType()); if (contentLength != null) { headers.setContentLength(contentLength); diff --git a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java index a906da520d0..6fda91d29b1 100644 --- a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java @@ -132,7 +132,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest { this.headers.setContentType(newContentType); } } - if (this.headers.getContentLength() == -1) { + if (this.headers.getContentLength() < 0) { int requestContentLength = this.servletRequest.getContentLength(); if (requestContentLength != -1) { this.headers.setContentLength(requestContentLength); diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 2601d2f916e..8c7c04334f2 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -773,7 +773,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat if (!requestHeaders.isEmpty()) { httpHeaders.putAll(requestHeaders); } - if (httpHeaders.getContentLength() == -1) { + if (httpHeaders.getContentLength() < 0) { httpHeaders.setContentLength(0L); } }