/** Return a copy of the response with the entity decompressed. */ public HttpResponse decompress() throws IOException { String enc = header("Content-Encoding"); return (enc != null && enc.contains("gzip")) ? unzip() : this; }
/** * Return the value for a date header. The return value will be null if the header does * not exist or if it cannot be parsed correctly as a date. */ public Instant dateHeader(String k) { String d = header(k); return (d == null) ? null : parseDate(d); }
/** Return a copy of the response with the entity decompressed. */ public HttpResponse decompress() throws IOException { String enc = header("Content-Encoding"); return (enc != null && enc.contains("gzip")) ? unzip() : this; }
/** * Return the value for a date header. The return value will be null if the header does * not exist or if it cannot be parsed correctly as a date. */ public Instant dateHeader(String k) { String d = header(k); return (d == null) ? null : parseDate(d); }
@Test public void header() { Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Type", Collections.singletonList("application/json")); HttpResponse res = new HttpResponse(200, headers); Assertions.assertEquals("application/json", res.header("content-type")); Assertions.assertEquals("application/json", res.header("Content-Type")); }
@Test public void decompress() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Type", Collections.singletonList("application/json")); headers.put("Content-Encoding", Collections.singletonList("gzip")); byte[] entity = HttpUtils.gzip("foo bar baz foo bar baz".getBytes(StandardCharsets.UTF_8)); HttpResponse res = new HttpResponse(200, headers, entity); Assertions.assertEquals("foo bar baz foo bar baz", res.decompress().entityAsString()); Assertions.assertNull(res.decompress().header("content-encoding")); }