private static Map < String , String > getOrderedHeadersToSign ( Header [ ] headers ) { Map < String , String > unique = new TreeMap <> ( ) ; for ( Header header : headers ) { String key = header . getName ( ) . toLowerCase ( Locale . US ) . trim ( ) ; if ( key . equals ( "connection" ) ) { // do not sign 'connection' header, it is very likely to be changed en-route. continue ; } String value = header . getValue ( ) ; if ( value == null ) { value = "" ; } else { // minimize white space value = value . trim ( ) . replaceAll ( "\\s+" , " " ) ; } // merge all values with same header name String prior = unique . get ( key ) ; if ( prior != null ) { if ( prior . length ( ) > 0 ) { value = prior + ' ' + value ; } unique . put ( key , value ) ; } else { unique . put ( key , value ) ; } } return unique ; }
Get the ordered map of headers to sign .