Skip to content

Commit

Permalink
Merge pull request #9 from ikikko/master
Browse files Browse the repository at this point in the history
JENKINS-17684 Remove Content-Type header when 304 not modified.
  • Loading branch information
jglick committed May 30, 2013
2 parents b844d0d + bbaf8fa commit 7e57b9d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/java/winstone/WinstoneResponse.java
Expand Up @@ -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());
Expand Down
38 changes: 36 additions & 2 deletions src/test/winstone/WinstoneResponseTest.java
@@ -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 {

Expand All @@ -19,4 +21,36 @@ public class WinstoneResponseTest {
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.