@Test public void keepAliveReturnsTrueWhenHttpConnectionMustBeKeptAlive() { HttpHeaders connectionHeaderAbsent = requestBuilder().build().headers(); HttpHeaders connectionHeaderClose = requestBuilder() .header(CONNECTION, CLOSE) .build() .headers(); HttpHeaders connectionHeaderKeepAlive = requestBuilder() .header(CONNECTION, KEEP_ALIVE) .build() .headers(); assertThat(keepAlive(connectionHeaderAbsent, HTTP_1_0), is(false)); assertThat(keepAlive(connectionHeaderAbsent, HTTP_1_1), is(true)); assertThat(keepAlive(connectionHeaderClose, HTTP_1_0), is(false)); assertThat(keepAlive(connectionHeaderClose, HTTP_1_1), is(false)); assertThat(keepAlive(connectionHeaderKeepAlive, HTTP_1_0), is(true)); assertThat(keepAlive(connectionHeaderKeepAlive, HTTP_1_1), is(true)); }
public static boolean keepAlive(HttpHeaders headers, HttpVersion version) { Optional<String> connection = headers.get(CONNECTION); if (connection.isPresent()) { if (CLOSE.toString().equalsIgnoreCase(connection.get())) { return false; } if (KEEP_ALIVE.toString().equalsIgnoreCase(connection.get())) { return true; } } return version.isKeepAliveDefault(); }
HttpMessageSupport { public static boolean keepAlive(HttpHeaders headers, HttpVersion version) { Optional<String> connection = headers.get(CONNECTION); if (connection.isPresent()) { if (CLOSE.toString().equalsIgnoreCase(connection.get())) { return false; } if (KEEP_ALIVE.toString().equalsIgnoreCase(connection.get())) { return true; } } return version.isKeepAliveDefault(); } }
HttpMessageSupport { public static boolean keepAlive(HttpHeaders headers, HttpVersion version) { Optional<String> connection = headers.get(CONNECTION); if (connection.isPresent()) { if (CLOSE.toString().equalsIgnoreCase(connection.get())) { return false; } if (KEEP_ALIVE.toString().equalsIgnoreCase(connection.get())) { return true; } } return version.isKeepAliveDefault(); } private  HttpMessageSupport(); }
HttpMessageSupport { public static boolean keepAlive(HttpHeaders headers, HttpVersion version) { Optional<String> connection = headers.get(CONNECTION); if (connection.isPresent()) { if (CLOSE.toString().equalsIgnoreCase(connection.get())) { return false; } if (KEEP_ALIVE.toString().equalsIgnoreCase(connection.get())) { return true; } } return version.isKeepAliveDefault(); } private  HttpMessageSupport(); static boolean chunked(HttpHeaders headers); static boolean keepAlive(HttpHeaders headers, HttpVersion version); }
HttpMessageSupport { public static boolean keepAlive(HttpHeaders headers, HttpVersion version) { Optional<String> connection = headers.get(CONNECTION); if (connection.isPresent()) { if (CLOSE.toString().equalsIgnoreCase(connection.get())) { return false; } if (KEEP_ALIVE.toString().equalsIgnoreCase(connection.get())) { return true; } } return version.isKeepAliveDefault(); } private  HttpMessageSupport(); static boolean chunked(HttpHeaders headers); static boolean keepAlive(HttpHeaders headers, HttpVersion version);  }