@Test public void testResponseDateInvalidInput() throws Exception { final ResponseDate interceptor = new ResponseDate(); try { interceptor.process(null, null, null); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException ex) { // expected } }
public static HttpProcessorBuilder customServer(final String serverInfo) { return HttpProcessorBuilder.create() .addAll( new ResponseDate(), new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", Http2Processors.class)), new H2ResponseContent(), new H2ResponseConnControl()) .addAll( new H2RequestValidateHost()); }
/** * Creates {@link HttpProcessorBuilder} initialized with default protocol interceptors * for server side HTTP/1.1 processing. * * @param serverInfo the server info text or {@code null} for default. * @return the processor builder. */ public static HttpProcessorBuilder customServer(final String serverInfo) { return HttpProcessorBuilder.create() .addAll( new ResponseDate(), new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new ResponseContent(), new ResponseConnControl()) .addAll( new RequestValidateHost()); }
@Test public void testResponseDateGenerated() throws Exception { final HttpContext context = new BasicHttpContext(null); final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK"); final ResponseDate interceptor = new ResponseDate(); interceptor.process(response, response.getEntity(), context); final Header h1 = response.getFirstHeader(HttpHeaders.DATE); Assert.assertNotNull(h1); interceptor.process(response, response.getEntity(), context); final Header h2 = response.getFirstHeader(HttpHeaders.DATE); Assert.assertNotNull(h2); }
/** * Creates {@link HttpProcessorBuilder} initialized with default protocol interceptors * for server side HTTP/1.1 processing. * * @param serverInfo the server info text or {@code null} for default. * @return the processor builder. */ public static HttpProcessorBuilder customServer(final String serverInfo) { return HttpProcessorBuilder.create() .addAll( new ResponseDate(), new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new ResponseContent(), new ResponseConnControl()) .addAll( new RequestValidateHost()); }
@Test public void testResponseDateNotGenerated() throws Exception { final HttpContext context = new BasicHttpContext(null); final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK"); response.setCode(199); final ResponseDate interceptor = new ResponseDate(); interceptor.process(response, response.getEntity(), context); final Header h1 = response.getFirstHeader(HttpHeaders.DATE); Assert.assertNull(h1); }