### Question:
HttpRequestFactory { public HttpRequest createHttpRequest(Request<?> request, ClientConfiguration clientConfiguration, ExecutionContext context) { final URI endpoint = request.getEndpoint(); String uri = HttpUtils.appendUri(endpoint.toString(), request.getResourcePath(), true); final String encodedParams = HttpUtils.encodeParameters(request); HttpMethodName method = request.getHttpMethod(); final boolean requestAlreadyHasPayload = request.getContent() != null; final boolean requestIsPost = method == HttpMethodName.POST; final boolean putParamsInUri = !requestIsPost || requestAlreadyHasPayload; if (encodedParams != null && putParamsInUri) { uri += "?" + encodedParams; } final Map<String, String> headers = new HashMap<String, String>(); configureHeaders(headers, request, context, clientConfiguration); InputStream is = request.getContent(); if (method == HttpMethodName.PATCH) { method = HttpMethodName.POST; headers.put("X-HTTP-Method-Override", HttpMethodName.PATCH.toString()); } if (method == HttpMethodName.POST) { if (request.getContent() == null && encodedParams != null) { final byte[] contentBytes = encodedParams.getBytes(StringUtils.UTF8); is = new ByteArrayInputStream(contentBytes); headers.put("Content-Length", String.valueOf(contentBytes.length)); } } if (clientConfiguration.isEnableGzip() && headers.get("Accept-Encoding") == null) { headers.put("Accept-Encoding", "gzip"); } else { headers.put("Accept-Encoding", "identity"); } final HttpRequest httpRequest = new HttpRequest(method.toString(), URI.create(uri), headers, is); httpRequest.setStreaming(request.isStreaming()); return httpRequest; }  HttpRequest createHttpRequest(Request<?> request,
            ClientConfiguration clientConfiguration, ExecutionContext context);  }### Answer:
@Test public void testContextUserAgent() { final String contextUserAgent = "context_user_agent"; context.setContextUserAgent(contextUserAgent); final HttpRequest httpRequest = factory.createHttpRequest(request, clientConfiguration, context); final String userAgent = httpRequest.getHeaders().get(HttpHeader.USER_AGENT); assertTrue("context user agent", userAgent.endsWith(contextUserAgent)); }
@Test public void testHeaders() { final HttpRequest httpRequest = factory.createHttpRequest(request, clientConfiguration, context); final Map<String, String> headers = httpRequest.getHeaders(); assertNotNull(headers.get(HttpHeader.HOST)); assertNotNull(headers.get(HttpHeader.CONTENT_TYPE)); }
@Test public void testEnableCompression() { clientConfiguration.withEnableGzip(true); final HttpRequest httpRequest = factory.createHttpRequest(request, clientConfiguration, context); final Map<String, String> headers = httpRequest.getHeaders(); assertEquals("accept encoding is gzip", "gzip", headers.get("Accept-Encoding")); }