public static ContinueResponseSender createResponseSender ( final HttpServerExchange exchange ) throws IOException { if ( ! exchange . isResponseChannelAvailable ( ) ) { throw UndertowMessages . MESSAGES . cannotSendContinueResponse ( ) ; } if ( exchange . getAttachment ( ALREADY_SENT ) != null ) { return new ContinueResponseSender ( ) { @ Override public boolean send ( ) throws IOException { return true ; } @ Override public void awaitWritable ( ) throws IOException { } @ Override public void awaitWritable ( long time , TimeUnit timeUnit ) throws IOException { } } ; } HttpServerExchange newExchange = exchange . getConnection ( ) . sendOutOfBandResponse ( exchange ) ; exchange . putAttachment ( ALREADY_SENT , true ) ; newExchange . setStatusCode ( StatusCodes . CONTINUE ) ; newExchange . getResponseHeaders ( ) . put ( Headers . CONTENT_LENGTH , 0 ) ; final StreamSinkChannel responseChannel = newExchange . getResponseChannel ( ) ; return new ContinueResponseSender ( ) { boolean shutdown = false ; @ Override public boolean send ( ) throws IOException { if ( ! shutdown ) { shutdown = true ; responseChannel . shutdownWrites ( ) ; } return responseChannel . flush ( ) ; } @ Override public void awaitWritable ( ) throws IOException { responseChannel . awaitWritable ( ) ; } @ Override public void awaitWritable ( final long time , final TimeUnit timeUnit ) throws IOException { responseChannel . awaitWritable ( time , timeUnit ) ; } } ; }
Creates a response sender that can be used to send a HTTP 100 - continue response .