Java HTTP Header copyHttpHeaders(@Nonnull final HttpURLConnection aConn, @Nonnull final InternetHeaders aHeaders)

Here you can find the source of copyHttpHeaders(@Nonnull final HttpURLConnection aConn, @Nonnull final InternetHeaders aHeaders)

Description

Copy headers from an Http connection to an InternetHeaders object

License

Open Source License

Parameter

Parameter Description
aConn Connection
aHeaders Headers

Declaration

public static void copyHttpHeaders(@Nonnull final HttpURLConnection aConn,
        @Nonnull final InternetHeaders aHeaders) 

Method Source Code

//package com.java2s;

import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;

import javax.mail.internet.InternetHeaders;

public class Main {
    /**/*from  w w  w .j  av  a2 s  .  c  o m*/
     * Copy headers from an Http connection to an InternetHeaders object
     *
     * @param aConn
     *        Connection
     * @param aHeaders
     *        Headers
     */
    public static void copyHttpHeaders(@Nonnull final HttpURLConnection aConn,
            @Nonnull final InternetHeaders aHeaders) {
        for (final Map.Entry<String, List<String>> aConnHeader : aConn.getHeaderFields().entrySet()) {
            final String sHeaderName = aConnHeader.getKey();
            if (sHeaderName != null)
                for (final String sHeaderValue : aConnHeader.getValue()) {
                    if (aHeaders.getHeader(sHeaderName) == null)
                        aHeaders.setHeader(sHeaderName, sHeaderValue);
                    else
                        aHeaders.addHeader(sHeaderName, sHeaderValue);
                }
        }
    }
}

Related

  1. addCustomHeaders(HttpURLConnection conn, Map headers)
  2. addHeader(HttpURLConnection conn, String headerName, String value)
  3. addHeadersToRequest(HttpURLConnection request, Map headers)
  4. createHttpConnection(URL endpointUrl, String httpMethod, Map headers)
  5. delete(String url, Map headers)
  6. doDelete(URL endpoint, Map headers)
  7. dumpHeaders(HttpURLConnection conn)