Refine search
/** * Determine whether the given response indicates a GZIP response. * <p>The default implementation checks whether the HTTP "Content-Encoding" * header contains "gzip" (in any casing). * @param httpResponse the resulting HttpResponse to check * @return whether the given response indicates a GZIP response */ protected boolean isGzipResponse(HttpResponse httpResponse) { Header encodingHeader = httpResponse.getFirstHeader(HTTP_HEADER_CONTENT_ENCODING); return (encodingHeader != null && encodingHeader.getValue() != null && encodingHeader.getValue().toLowerCase().contains(ENCODING_GZIP)); }
/** * Determine whether the given response indicates a GZIP response. * <p>The default implementation checks whether the HTTP "Content-Encoding" * header contains "gzip" (in any casing). * @param httpResponse the resulting HttpResponse to check * @return whether the given response indicates a GZIP response */ protected boolean isGzipResponse(HttpResponse httpResponse) { Header encodingHeader = httpResponse.getFirstHeader(HTTP_HEADER_CONTENT_ENCODING); return (encodingHeader != null && encodingHeader.getValue() != null && encodingHeader.getValue().toLowerCase().contains(ENCODING_GZIP)); }
private boolean isGzipResponse(HttpResponse httpResponse) { Header encodingHeader = httpResponse.getFirstHeader(HTTP_HEADER_CONTENT_ENCODING); return (encodingHeader != null && encodingHeader.getValue() != null && encodingHeader.getValue().toLowerCase().contains(ENCODING_GZIP)); }
private String getBody(HttpResponse response) throws Exception { Charset charset = null; try { String contentTypeStr = response.getFirstHeader("Content-type").getValue(); if (StringUtil.isNotEmpty(contentTypeStr)) { ContentType contentType = ContentType.parse(contentTypeStr); charset = contentType.getCharset(); } } catch (Exception ignore) { } return EntityUtils.toString(response.getEntity(), charset != null ? charset : DEFAULT_CHARSET); }
@Test public void shouldSupportGetFirstHeader() throws Exception { HttpResponse resp = new TestHttpResponse(304, "REDIRECTED", new BasicHeader("Location", "http://bar.com")); assertThat(resp.getFirstHeader("None")).isNull(); assertThat(new TestHttpResponse(200, "OK").getFirstHeader("Foo")).isNull(); for (String l : new String[] { "location", "Location" }) { assertThat(resp.getFirstHeader(l).getValue()).isEqualTo("http://bar.com"); } }
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); response.getEntity().writeTo(outstream); assertThat(new String(outstream.toByteArray()), is("hello")); } });
@Override public void run() throws IOException { org.apache.http.HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("foo.response")); } });
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader(HttpHeaders.CONTENT_TYPE); assertThat(header.getValue(), is("text/plain")); } });
@Test public void should_expected_response_header() throws IOException { runWithConfiguration("foo.json"); HttpResponse response = helper.getResponse(remoteUrl("/response_header")); assertThat(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(), is("application/json")); assertThat(response.getFirstHeader("foo").getValue(), is("bar")); }
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); } });
@Override public void run() throws Exception { Header header = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE); assertThat(header.getValue(), is("text/html")); } });
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); } });
@Override public void run() throws IOException { String json = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); assertThat(json, is("application/json")); String bar = helper.getResponse(root()).getFirstHeader("foo").getValue(); assertThat(bar, is("bar")); } });
@Override public void run() throws Exception { Header header = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE); assertThat(header.getValue(), is("text/html")); } });
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); } });
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); response = helper.getResponse(root()); header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); } });
@Override public void run() throws IOException { String value = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); assertThat(value, is("application/json")); } });
@Override public void run() throws Exception { HttpResponse response = helper.getResponse(root()); Header header = response.getFirstHeader("foo"); assertThat(header.getValue(), is("bar")); } });
@Override public void run() throws Exception { Header header = helper.getResponse(root()).getFirstHeader(HttpHeaders.CONTENT_TYPE); assertThat(header.getValue(), is("text/plain; charset=utf-8")); } });
@Test public void should_mount_dir_to_uri_with_response() throws IOException { runWithConfiguration("mount.json"); org.apache.http.HttpResponse httpResponse = helper.getResponse(remoteUrl("/mount-response/mount.response")); String value = httpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); assertThat(value, is("text/plain")); String content = CharStreams.toString(new InputStreamReader(httpResponse.getEntity().getContent())); assertThat(content, is("response from mount")); } }