private void copyHeadersFromClient(HttpServletRequest pRequest, HttpURLConnection pRemoteConnection) {
        Enumeration headerNames = pRequest.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = (String) headerNames.nextElement();
            Enumeration headerValues = pRequest.getHeaders(headerName);

            // Skip the "host" header, as we want something else
            if (HTTP_REQUEST_HEADER_HOST.equalsIgnoreCase(headerName)) {
                // Skip this header
                headerName = null;
            }

            // Set the the header to the remoteConnection
            if (headerName != null) {
                // Convert from multiple line to single line, comma separated, as
                // there seems to be a shortcoming in the URLConneciton API...
                StringBuilder headerValue = new StringBuilder();
                while (headerValues.hasMoreElements()) {
                    String value = (String) headerValues.nextElement();
                    headerValue.append(value);
                    if (headerValues.hasMoreElements()) {
                        headerValue.append(", ");
                    }
                }

                //System.out.println("client -->>> remote: " + headerName + ": " + headerValue);
                pRemoteConnection.setRequestProperty(headerName, headerValue.toString());
            }
        }
    }
private void copyHeadersFromClient ( HttpServletRequest pRequest , HttpURLConnection pRemoteConnection ) { Enumeration headerNames = pRequest . getHeaderNames ( ) ; while ( headerNames . hasMoreElements ( ) ) { String headerName = ( String ) headerNames . nextElement ( ) ; Enumeration headerValues = pRequest . getHeaders ( headerName ) ; if ( HTTP_REQUEST_HEADER_HOST . equalsIgnoreCase ( headerName ) ) { headerName = null ; } if ( headerName != null ) { StringBuilder headerValue = new StringBuilder ( ) ; while ( headerValues . hasMoreElements ( ) ) { String value = ( String ) headerValues . nextElement ( ) ; headerValue . append ( value ) ; if ( headerValues . hasMoreElements ( ) ) { headerValue . append ( ", " ) ; } } pRemoteConnection . setRequestProperty ( headerName , headerValue . toString ( ) ) ; } } }
Copies headers from the client (the incoming {@code HttpServletRequest})
to the outgoing connection.
All headers except the "Host" header are copied.

@param pRequest
@param pRemoteConnection