Example usage for io.netty.handler.codec DateFormatter parseHttpDate

List of usage examples for io.netty.handler.codec DateFormatter parseHttpDate

Introduction

In this page you can find the example usage for io.netty.handler.codec DateFormatter parseHttpDate.

Prototype

public static Date parseHttpDate(CharSequence txt) 

Source Link

Document

Parse some text into a Date , according to RFC6265

Usage

From source file:com.linecorp.armeria.common.StringValueConverter.java

License:Apache License

@Override
public long convertToTimeMillis(String value) {
    final Date date = DateFormatter.parseHttpDate(value);
    if (date == null) {
        throw new IllegalArgumentException("not a date: " + value);
    }//from w  ww  . j  a va  2s  . co  m
    return date.getTime();
}

From source file:com.linecorp.armeria.server.file.HttpFileServiceTest.java

License:Apache License

private static String assert200Ok(CloseableHttpResponse res, @Nullable String expectedContentType,
        String expectedContent) throws Exception {

    assertStatusLine(res, "HTTP/1.1 200 OK");

    // Ensure that the 'Last-Modified' header exists and is well-formed.
    final String lastModified;
    assertThat(res.containsHeader(HttpHeaders.LAST_MODIFIED)).isTrue();
    lastModified = res.getFirstHeader(HttpHeaders.LAST_MODIFIED).getValue();
    DateFormatter.parseHttpDate(lastModified);

    // Ensure the content and its type are correct.
    assertThat(EntityUtils.toString(res.getEntity()).trim()).isEqualTo(expectedContent);

    if (expectedContentType != null) {
        assertThat(res.containsHeader(HttpHeaders.CONTENT_TYPE)).isTrue();
        assertThat(res.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()).startsWith(expectedContentType);
    } else {/*from   w ww  .java2s .c o m*/
        assertThat(res.containsHeader(HttpHeaders.CONTENT_TYPE)).isFalse();
    }

    return lastModified;
}