private static void addCanonicalizedHeaders ( final HttpURLConnection conn , final StringBuilder canonicalizedString ) { // Look for header names that start with // HeaderNames.PrefixForStorageHeader // Then sort them in case-insensitive manner. final Map < String , List < String > > headers = conn . getRequestProperties ( ) ; final ArrayList < String > httpStorageHeaderNameArray = new ArrayList < String > ( ) ; for ( final String key : headers . keySet ( ) ) { if ( key . toLowerCase ( Utility . LOCALE_US ) . startsWith ( Constants . PREFIX_FOR_STORAGE_HEADER ) ) { httpStorageHeaderNameArray . add ( key . toLowerCase ( Utility . LOCALE_US ) ) ; } } Collections . sort ( httpStorageHeaderNameArray ) ; // Now go through each header's values in the sorted order and append // them to the canonicalized string. for ( final String key : httpStorageHeaderNameArray ) { final StringBuilder canonicalizedElement = new StringBuilder ( key ) ; String delimiter = ":" ; final ArrayList < String > values = getHeaderValues ( headers , key ) ; boolean appendCanonicalizedElement = false ; // Go through values, unfold them, and then append them to the // canonicalized element string. for ( final String value : values ) { if ( value != null ) { appendCanonicalizedElement = true ; } // Unfolding is simply removal of CRLF. final String unfoldedValue = CRLF . matcher ( value ) . replaceAll ( Matcher . quoteReplacement ( Constants . EMPTY_STRING ) ) ; // Append it to the canonicalized element string. canonicalizedElement . append ( delimiter ) ; canonicalizedElement . append ( unfoldedValue ) ; delimiter = "," ; } // Now, add this canonicalized element to the canonicalized header // string. if ( appendCanonicalizedElement ) { appendCanonicalizedElement ( canonicalizedString , canonicalizedElement . toString ( ) ) ; } } }
Add x - ms - prefixed headers in a fixed order .