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

com.appland.appmap.reflect.HttpHeaders Maven / Gradle / Ivy

package com.appland.appmap.reflect;

import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public interface HttpHeaders {
  HttpHeaderDelegate getHeaderDelegate();

  default String getHeader(String name) {
    HttpHeaderDelegate delegate = getHeaderDelegate();
    return delegate.fnGetHeader != null?
    (String) delegate.invokeWrappedMethod(delegate.fnGetHeader, name)
    : "";
  }
  
  @SuppressWarnings("unchecked")
  default Enumeration getHeaderNames() {
    HttpHeaderDelegate delegate = getHeaderDelegate();
    try {
      return (Enumeration) delegate.invokeWrappedMethod(delegate.fnGetHeaderNames);
    } catch (ClassCastException _e) {
      return Collections.enumeration((Collection)delegate.invokeWrappedMethod(delegate.fnGetHeaderNames));
    } catch (Exception e) {
      // Fall through
    }

    return Collections.enumeration(Collections.emptyList());
  }

  /**
   * Non-standard utility method. Retrieves all headers.
   */
  default Map getHeaders() {
    HashMap headers = new HashMap<>();

    for (Enumeration e = getHeaderNames(); e.hasMoreElements();) {
      String headerName = (String) e.nextElement();
      headers.put(headerName, this.getHeader(headerName));
    }

    return headers;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy