INT-3063: 'Expires' HTTP header workaround
According to RFC 2616 HTTP clients should ignore invalid values for date-aware header, but Spring MVC `HttpHeaders` raises `IllegalArgumentException` in this case. Proposal fix to Spring Integration just to `try...catch` call of `HttpHeaders.getExpires()` and `return null`. JIRA: https://jira.springsource.org/browse/INT-3063
This commit is contained in:
committed by
Gary Russell
parent
9737888e57
commit
70ceab379f
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -58,6 +58,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanFactoryAware, InitializingBean{
|
||||
@@ -826,8 +827,17 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
|
||||
return (StringUtils.hasText(eTag)) ? eTag : null;
|
||||
}
|
||||
else if (EXPIRES.equalsIgnoreCase(name)) {
|
||||
long expires = source.getExpires();
|
||||
return (expires > -1) ? expires : null;
|
||||
try {
|
||||
long expires = source.getExpires();
|
||||
return (expires > -1) ? expires : null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if(logger.isDebugEnabled()) {
|
||||
logger.debug(e.getMessage());
|
||||
}
|
||||
// According to RFC 2616
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (IF_NONE_MATCH.equalsIgnoreCase(name)) {
|
||||
return source.getIfNoneMatch();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.integration.http.support;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
@@ -32,6 +32,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
@@ -41,6 +42,7 @@ import org.springframework.util.CollectionUtils;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
@@ -657,4 +659,13 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
|
||||
assertNull(headers.get("Content-Length"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInt3063InvalidExpiresHeader() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Expires", "-1");
|
||||
Map<String, Object> messageHeaders = DefaultHttpHeaderMapper.outboundMapper().toHeaders(headers);
|
||||
assertEquals(0, messageHeaders.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user