All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mercadopago.net.KeepAliveStrategy Maven / Gradle / Ivy

There is a newer version: 2.1.29
Show newest version
package com.mercadopago.net;

import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator;
import org.apache.http.HttpResponse;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.message.BasicHeaderElementIterator;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;

/** KeepAliveStrategy class. */
public class KeepAliveStrategy implements ConnectionKeepAliveStrategy {

  private static final int DEFAULT_KEEP_ALIVE_TIMEOUT_MS = 10000;

  private static final String KEEP_ALIVE_TIMEOUT_PARAM_NAME = "timeout";

  @Override
  public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
    HeaderElementIterator it =
        new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
      HeaderElement he = it.nextElement();
      String param = he.getName();
      String value = he.getValue();
      if (value != null && param.equalsIgnoreCase(KEEP_ALIVE_TIMEOUT_PARAM_NAME)) {
        return Long.parseLong(value) * 1000;
      }
    }
    return DEFAULT_KEEP_ALIVE_TIMEOUT_MS;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy