Skip to content

Commit

Permalink
Issue #6544 - More updates based on review and merge
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Jul 30, 2021
1 parent 4d35dd7 commit 3868360
Showing 1 changed file with 17 additions and 26 deletions.
Expand Up @@ -16,7 +16,6 @@
import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpHeader;
Expand Down Expand Up @@ -68,8 +67,9 @@ public void testGzipDefault() throws Exception

startHttpClient();
ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));
assertThat("Ensure that gzip is working", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), containsString("gzip"));
String responseDetails = toResponseDetails(response);
assertEquals(HttpStatus.OK_200, response.getStatus(), responseDetails);
assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_ENCODING), containsString("gzip"));
}
}
}
Expand Down Expand Up @@ -111,9 +111,10 @@ public void testGzipDefaultExcludedMimeType() throws Exception

startHttpClient();
ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/jetty.webp");
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));
assertThat("Correct Content-Type", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/webp"));
assertThat("Ensure that gzip exclusion worked", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip")));
String responseDetails = toResponseDetails(response);
assertEquals(HttpStatus.OK_200, response.getStatus(), responseDetails);
assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/webp"));
assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip")));
}
}
}
Expand Down Expand Up @@ -156,30 +157,20 @@ public void testGzipAddWebappSpecificExcludeMimeType() throws Exception

startHttpClient();
ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/jetty.icon");
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));
assertThat("Ensure that gzip exclusion worked", response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip")));
assertThat("Correct Content-Type", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/vnd.microsoft.icon"));
String responseDetails = toResponseDetails(response);
assertEquals(HttpStatus.OK_200, response.getStatus(), responseDetails);
assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_ENCODING), not(containsString("gzip")));
assertThat(responseDetails, response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("image/vnd.microsoft.icon"));
}
}
}

private static class ResponseDetails implements Supplier<String>
private static String toResponseDetails(ContentResponse response)
{
private final ContentResponse response;

public ResponseDetails(ContentResponse response)
{
this.response = response;
}

@Override
public String get()
{
StringBuilder ret = new StringBuilder();
ret.append(response.toString()).append(System.lineSeparator());
ret.append(response.getHeaders().toString()).append(System.lineSeparator());
ret.append(response.getContentAsString()).append(System.lineSeparator());
return ret.toString();
}
StringBuilder ret = new StringBuilder();
ret.append(response.toString()).append(System.lineSeparator());
ret.append(response.getHeaders().toString()).append(System.lineSeparator());
ret.append(response.getContentAsString()).append(System.lineSeparator());
return ret.toString();
}
}

0 comments on commit 3868360

Please sign in to comment.