public Map < String , String > getHeaders ( ) { final Map < String , String > headers = new HashMap < String , String > ( request . headers ( ) . entries ( ) . size ( ) ) ; for ( final Entry < String , String > header : request . headers ( ) . entries ( ) ) { // http://tools.ietf.org/html/rfc2616#section-4.2 if ( headers . containsKey ( header . getKey ( ) ) ) { headers . put ( header . getKey ( ) , headers . get ( header . getKey ( ) ) + "," + header . getValue ( ) ) ; } else { headers . put ( header . getKey ( ) , header . getValue ( ) ) ; } } return headers ; }
Copies the header list so modifications won t affect the original set . Note that it flattens duplicate headers keys as comma separated lists per the RFC