40
40
41
41
import org .elasticsearch .ElasticsearchException ;
42
42
import org .elasticsearch .common .bytes .BytesArray ;
43
+ import org .elasticsearch .common .collect .Iterators ;
43
44
import org .elasticsearch .common .network .NetworkAddress ;
44
45
import org .elasticsearch .common .network .NetworkService ;
45
46
import org .elasticsearch .common .settings .ClusterSettings ;
46
47
import org .elasticsearch .common .settings .Setting ;
47
48
import org .elasticsearch .common .settings .Settings ;
48
49
import org .elasticsearch .common .transport .TransportAddress ;
49
50
import org .elasticsearch .common .unit .ByteSizeValue ;
50
- import org .elasticsearch .common .util .MockPageCacheRecycler ;
51
- import org .elasticsearch .common .util .PageCacheRecycler ;
52
51
import org .elasticsearch .common .util .concurrent .ThreadContext ;
53
52
import org .elasticsearch .core .TimeValue ;
54
53
import org .elasticsearch .http .AbstractHttpServerTransportTestCase ;
57
56
import org .elasticsearch .http .HttpServerTransport ;
58
57
import org .elasticsearch .http .HttpTransportSettings ;
59
58
import org .elasticsearch .http .NullDispatcher ;
59
+ import org .elasticsearch .rest .ChunkedRestResponseBody ;
60
60
import org .elasticsearch .rest .RestChannel ;
61
61
import org .elasticsearch .rest .RestRequest ;
62
62
import org .elasticsearch .rest .RestResponse ;
66
66
import org .elasticsearch .tracing .Tracer ;
67
67
import org .elasticsearch .transport .netty4 .NettyAllocator ;
68
68
import org .elasticsearch .transport .netty4 .SharedGroupFactory ;
69
+ import org .elasticsearch .xcontent .ToXContent ;
69
70
import org .junit .After ;
70
71
import org .junit .Before ;
71
72
@@ -94,14 +95,12 @@ public class Netty4HttpServerTransportTests extends AbstractHttpServerTransportT
94
95
95
96
private NetworkService networkService ;
96
97
private ThreadPool threadPool ;
97
- private PageCacheRecycler recycler ;
98
98
private ClusterSettings clusterSettings ;
99
99
100
100
@ Before
101
101
public void setup () throws Exception {
102
102
networkService = new NetworkService (Collections .emptyList ());
103
103
threadPool = new TestThreadPool ("test" );
104
- recycler = new MockPageCacheRecycler (Settings .EMPTY );
105
104
clusterSettings = randomClusterSettings ();
106
105
}
107
106
@@ -112,7 +111,6 @@ public void shutdown() throws Exception {
112
111
}
113
112
threadPool = null ;
114
113
networkService = null ;
115
- recycler = null ;
116
114
clusterSettings = null ;
117
115
}
118
116
@@ -560,6 +558,67 @@ protected void initChannel(SocketChannel ch) {
560
558
}
561
559
}
562
560
561
+ public void testHeadRequestToChunkedApi () throws InterruptedException {
562
+ final HttpServerTransport .Dispatcher dispatcher = new HttpServerTransport .Dispatcher () {
563
+
564
+ @ Override
565
+ public void dispatchRequest (final RestRequest request , final RestChannel channel , final ThreadContext threadContext ) {
566
+ try {
567
+ channel .sendResponse (
568
+ new RestResponse (
569
+ OK ,
570
+ ChunkedRestResponseBody .fromXContent (
571
+ () -> Iterators .single (
572
+ (builder , params ) -> { throw new AssertionError ("should not be called for HEAD REQUEST" ); }
573
+ ),
574
+ ToXContent .EMPTY_PARAMS ,
575
+ channel
576
+ )
577
+ )
578
+ );
579
+ } catch (IOException e ) {
580
+ throw new AssertionError (e );
581
+ }
582
+ }
583
+
584
+ @ Override
585
+ public void dispatchBadRequest (final RestChannel channel , final ThreadContext threadContext , final Throwable cause ) {
586
+ throw new AssertionError ();
587
+ }
588
+
589
+ };
590
+
591
+ final Settings settings = createSettings ();
592
+ try (
593
+ Netty4HttpServerTransport transport = new Netty4HttpServerTransport (
594
+ settings ,
595
+ networkService ,
596
+ threadPool ,
597
+ xContentRegistry (),
598
+ dispatcher ,
599
+ clusterSettings ,
600
+ new SharedGroupFactory (settings ),
601
+ Tracer .NOOP
602
+ )
603
+ ) {
604
+ transport .start ();
605
+ final TransportAddress remoteAddress = randomFrom (transport .boundAddress ().boundAddresses ());
606
+
607
+ try (Netty4HttpClient client = new Netty4HttpClient ()) {
608
+ final String url = "/some-head-endpoint" ;
609
+ final FullHttpRequest request = new DefaultFullHttpRequest (HttpVersion .HTTP_1_1 , HttpMethod .HEAD , url );
610
+
611
+ final FullHttpResponse response = client .send (remoteAddress .address (), request );
612
+ try {
613
+ assertThat (response .status (), equalTo (HttpResponseStatus .OK ));
614
+ assertFalse (response .content ().isReadable ());
615
+ } finally {
616
+ response .release ();
617
+ }
618
+ }
619
+ }
620
+ }
621
+
563
622
private Settings createSettings () {
564
623
return createBuilderWithPort ().build ();
565
624
}
0 commit comments