Skip to content
Permalink
Browse files

Merge pull request #9 from ikikko/master

JENKINS-17684 Remove Content-Type header when 304 not modified.
  • Loading branch information
jglick committed May 30, 2013
2 parents b844d0d + bbaf8fa commit 7e57b9d574818516c2a01c3807c60a90c4ea6594
Showing with 37 additions and 3 deletions.
  1. +1 −1 src/java/winstone/WinstoneResponse.java
  2. +36 −2 src/test/winstone/WinstoneResponseTest.java
@@ -240,7 +240,7 @@ public void validateHeaders() {

forceHeader(KEEP_ALIVE_HEADER, !closeAfterRequest() ? KEEP_ALIVE_OPEN : KEEP_ALIVE_CLOSE);
String contentType = getHeader(CONTENT_TYPE_HEADER);
if (this.statusCode != SC_MOVED_TEMPORARILY) {
if (this.statusCode != SC_MOVED_TEMPORARILY && this.statusCode != SC_NOT_MODIFIED) {
if (contentType == null) {
// Bypass normal encoding
forceHeader(CONTENT_TYPE_HEADER, "text/html;charset=" + getCharacterEncoding());
@@ -1,10 +1,12 @@
package winstone;

import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class WinstoneResponseTest {

@@ -19,4 +21,36 @@
assertTrue("expires date format", cookieAsString.matches(".*Expires=\\w{3}, \\d{1,2}-\\w{3}-\\d{4} \\d{1,2}:\\d{1,2}:\\d{1,2} GMT.*"));
}

@Test
public void testValidateHeadersWhenOk() throws Exception {
WinstoneResponse response = setupResponse(HttpServletResponse.SC_OK);

response.validateHeaders();
String contentType = response.getHeader(WinstoneResponse.CONTENT_TYPE_HEADER);

assertThat(contentType, containsString("text/html"));
}

@Test
public void testValidateHeadersWhenNotModified() throws Exception {
WinstoneResponse response = setupResponse(HttpServletResponse.SC_NOT_MODIFIED);

response.validateHeaders();
String contentType = response.getHeader(WinstoneResponse.CONTENT_TYPE_HEADER);

assertThat(contentType, is(nullValue()));
}

private WinstoneResponse setupResponse(int statusCode) {
WinstoneRequest request = new WinstoneRequest();
WinstoneResponse response = new WinstoneResponse();

response.setOutputStream(new WinstoneOutputStream(null, false));
response.setRequest(request);
response.setProtocol("HTTP/1.1");
response.setStatus(statusCode);

return response;
}

}

0 comments on commit 7e57b9d

Please sign in to comment.
You can’t perform that action at this time.