@Test public void constructRespondable_replaceContentLengthHeaderValue() throws Exception { String data = "hello, world"; Charset charset = StandardCharsets.UTF_8; byte[] bytes = data.getBytes(charset); long originalContentLengthValue = bytes.length * 2; MediaType contentType = MediaType.PLAIN_TEXT_UTF_8.withCharset(charset); Map<String, String> originalHeaders = ImmutableMap.of(HttpHeaders.CONTENT_TYPE, contentType.toString(), HttpHeaders.CONTENT_LENGTH, String.valueOf(originalContentLengthValue)); HttpRespondable respondable = HarBridgeEntryParser.constructRespondable(200, HarResponseData.of(originalHeaders.entrySet(), contentType, ByteSource.wrap(bytes))); Multimap<String, String> headersMm = ArrayListMultimap.create(); respondable.streamHeaders().forEach(h -> { headersMm.put(h.getKey(), h.getValue()); }); Map<String, Collection<String>> headers = headersMm.asMap(); Collection<String> values = headers.get(HttpHeaders.CONTENT_LENGTH); System.out.format("%s: %s%n", HttpHeaders.CONTENT_LENGTH, values); assertEquals("num values", 1, values.size()); String finalContentLengthStr = values.iterator().next(); assertNotNull("final content length header not found", finalContentLengthStr); long finalContentLength = Long.parseLong(finalContentLengthStr); assertEquals("content length", bytes.length, finalContentLength); }
protected static HttpRespondable constructRespondable(int status, HarResponseData responseData) throws IOException { Multimap<String, String> headers = ArrayListMultimap.create(); responseData.headers().forEach(header -> { headers.put(header.getKey(), header.getValue()); }); replaceContentLength(headers, responseData.getBody().size()); return HttpRespondable.inMemory(status, headers, responseData.getContentType(), responseData.getBody()); }
HarBridgeEntryParser implements EntryParser<E> { protected static HttpRespondable constructRespondable(int status, HarResponseData responseData) throws IOException { Multimap<String, String> headers = ArrayListMultimap.create(); responseData.headers().forEach(header -> { headers.put(header.getKey(), header.getValue()); }); replaceContentLength(headers, responseData.getBody().size()); return HttpRespondable.inMemory(status, headers, responseData.getContentType(), responseData.getBody()); } }
HarBridgeEntryParser implements EntryParser<E> { protected static HttpRespondable constructRespondable(int status, HarResponseData responseData) throws IOException { Multimap<String, String> headers = ArrayListMultimap.create(); responseData.headers().forEach(header -> { headers.put(header.getKey(), header.getValue()); }); replaceContentLength(headers, responseData.getBody().size()); return HttpRespondable.inMemory(status, headers, responseData.getContentType(), responseData.getBody()); } HarBridgeEntryParser(HarBridge<E> bridge, HarResponseEncoderFactory<E> responseEncoderFactory); }
HarBridgeEntryParser implements EntryParser<E> { protected static HttpRespondable constructRespondable(int status, HarResponseData responseData) throws IOException { Multimap<String, String> headers = ArrayListMultimap.create(); responseData.headers().forEach(header -> { headers.put(header.getKey(), header.getValue()); }); replaceContentLength(headers, responseData.getBody().size()); return HttpRespondable.inMemory(status, headers, responseData.getContentType(), responseData.getBody()); } HarBridgeEntryParser(HarBridge<E> bridge, HarResponseEncoderFactory<E> responseEncoderFactory); static HarBridgeEntryParser<E> withPlainEncoder(HarBridge<E> bridge); @Override ParsedRequest parseRequest(E harEntry); @Nullable Multimap<String, Optional<String>> parseQuery(URI uri); @Override HttpRespondable parseResponse(ParsedRequest request, E entry); }
HarBridgeEntryParser implements EntryParser<E> { protected static HttpRespondable constructRespondable(int status, HarResponseData responseData) throws IOException { Multimap<String, String> headers = ArrayListMultimap.create(); responseData.headers().forEach(header -> { headers.put(header.getKey(), header.getValue()); }); replaceContentLength(headers, responseData.getBody().size()); return HttpRespondable.inMemory(status, headers, responseData.getContentType(), responseData.getBody()); } HarBridgeEntryParser(HarBridge<E> bridge, HarResponseEncoderFactory<E> responseEncoderFactory); static HarBridgeEntryParser<E> withPlainEncoder(HarBridge<E> bridge); @Override ParsedRequest parseRequest(E harEntry); @Nullable Multimap<String, Optional<String>> parseQuery(URI uri); @Override HttpRespondable parseResponse(ParsedRequest request, E entry);  }