@ Override public Mono < HttpResponse > process ( HttpPipelineCallContext context , HttpPipelineNextPolicy next ) { final Flux < ByteBuf > contents = context . httpRequest ( ) . body ( ) == null ? Flux . just ( getEmptyBuffer ( ) ) : context . httpRequest ( ) . body ( ) ; return contents . defaultIfEmpty ( getEmptyBuffer ( ) ) . collect ( ( ) -> { try { return MessageDigest . getInstance ( "SHA-256" ) ; } catch ( NoSuchAlgorithmException e ) { throw Exceptions . propagate ( e ) ; } } , ( messageDigest , byteBuffer ) -> { if ( messageDigest != null ) { messageDigest . update ( byteBuffer . nioBuffer ( ) ) ; } } ) . flatMap ( messageDigest -> { final HttpHeaders headers = context . httpRequest ( ) . headers ( ) ; final String contentHash = Base64 . getEncoder ( ) . encodeToString ( messageDigest . digest ( ) ) ; // All three of these headers are used by ConfigurationClientCredentials to generate the // Authentication header value. So, we need to ensure that they exist. headers . set ( HOST_HEADER , context . httpRequest ( ) . url ( ) . getHost ( ) ) ; headers . set ( CONTENT_HASH_HEADER , contentHash ) ; if ( headers . value ( DATE_HEADER ) == null ) { String utcNow = OffsetDateTime . now ( ZoneOffset . UTC ) . format ( DateTimeFormatter . RFC_1123_DATE_TIME ) ; headers . set ( DATE_HEADER , utcNow ) ; } return next . process ( ) ; } ) ; }
Adds the required headers to authenticate a request to Azure Application Configuration service .