Example usage for com.squareup.okhttp.internal.http HttpDate parse

List of usage examples for com.squareup.okhttp.internal.http HttpDate parse

Introduction

In this page you can find the example usage for com.squareup.okhttp.internal.http HttpDate parse.

Prototype

public static Date parse(String value) 

Source Link

Document

Returns the date for value .

Usage

From source file:at.bitfire.dav4android.exception.ServiceUnavailableException.java

License:Open Source License

public ServiceUnavailableException(Response response) {
    super(response);

    // Retry-After  = "Retry-After" ":" ( HTTP-date | delta-seconds )
    // HTTP-date    = rfc1123-date | rfc850-date | asctime-date

    String strRetryAfter = response.header("Retry-After");
    if (strRetryAfter != null) {
        retryAfter = HttpDate.parse(strRetryAfter);

        if (retryAfter == null)
            // not a HTTP-date, must be delta-seconds
            try {
                int seconds = Integer.parseInt(strRetryAfter);

                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.SECOND, seconds);
                retryAfter = cal.getTime();

            } catch (NumberFormatException e) {
                Constants.log.warn("Received Retry-After which was not a HTTP-date nor delta-seconds");
            }/*from   ww  w  .ja v  a 2s  .c om*/
    }
}