private void copyRequestHeaders ( HttpServletRequest servletRequest , HttpRequest proxyRequest ) throws URISyntaxException { // Get an Enumeration of all of the header names sent by the client Enumeration < ? > enumerationOfHeaderNames = servletRequest . getHeaderNames ( ) ; while ( enumerationOfHeaderNames . hasMoreElements ( ) ) { String headerName = ( String ) enumerationOfHeaderNames . nextElement ( ) ; //Instead the content-length is effectively set via InputStreamEntity if ( ! headerName . equalsIgnoreCase ( CONTENT_LENGTH ) && ! hopByHopHeaders . containsHeader ( headerName ) ) { Enumeration < ? > headers = servletRequest . getHeaders ( headerName ) ; while ( headers . hasMoreElements ( ) ) { //sometimes more than one value String headerValue = ( String ) headers . nextElement ( ) ; // In case the proxy host is running multiple virtual servers, // rewrite the Host header to ensure that we get content from // the correct virtual server if ( headerName . equalsIgnoreCase ( HOST ) ) { HttpHost host = URIUtils . extractHost ( new URI ( prerenderConfig . getPrerenderServiceUrl ( ) ) ) ; headerValue = host . getHostName ( ) ; if ( host . getPort ( ) != - 1 ) { headerValue += ":" + host . getPort ( ) ; } } proxyRequest . addHeader ( headerName , headerValue ) ; } } } }
Copy request headers from the servlet client to the proxy request .