private < R > ChannelFuture createAndSendHttpRequest ( URI server , String uri , EtcdRequest < R > etcdRequest , Channel channel ) throws Exception { HttpRequest httpRequest = new DefaultHttpRequest ( HttpVersion . HTTP_1_1 , etcdRequest . getMethod ( ) , uri ) ; httpRequest . headers ( ) . add ( HttpHeaderNames . CONNECTION , "keep-alive" ) ; if ( ! this . config . hasHostName ( ) ) { httpRequest . headers ( ) . add ( HttpHeaderNames . HOST , server . getHost ( ) + ":" + server . getPort ( ) ) ; } else { httpRequest . headers ( ) . add ( HttpHeaderNames . HOST , this . config . getHostName ( ) ) ; } HttpPostRequestEncoder bodyRequestEncoder = null ; Map < String , String > keyValuePairs = etcdRequest . getRequestParams ( ) ; if ( keyValuePairs != null && ! keyValuePairs . isEmpty ( ) ) { HttpMethod etcdRequestMethod = etcdRequest . getMethod ( ) ; if ( etcdRequestMethod == HttpMethod . POST || etcdRequestMethod == HttpMethod . PUT ) { bodyRequestEncoder = new HttpPostRequestEncoder ( httpRequest , false ) ; for ( Map . Entry < String , String > entry : keyValuePairs . entrySet ( ) ) { bodyRequestEncoder . addBodyAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ; } httpRequest = bodyRequestEncoder . finalizeRequest ( ) ; } else { QueryStringEncoder encoder = new QueryStringEncoder ( uri ) ; for ( Map . Entry < String , String > entry : keyValuePairs . entrySet ( ) ) { encoder . addParam ( entry . getKey ( ) , entry . getValue ( ) ) ; } httpRequest . setUri ( encoder . toString ( ) ) ; } } etcdRequest . setHttpRequest ( httpRequest ) ; ChannelFuture future = channel . write ( httpRequest ) ; if ( bodyRequestEncoder != null && bodyRequestEncoder . isChunked ( ) ) { future = channel . write ( bodyRequestEncoder ) ; } channel . flush ( ) ; return future ; }
Get HttpRequest belonging to etcdRequest