File tree Expand file tree Collapse file tree 4 files changed +46
-7
lines changed
Elasticsearch.Net/Connection
ClientConcepts/Connection
Framework/Integration/Process Expand file tree Collapse file tree 4 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -144,29 +144,28 @@ protected virtual HttpRequestMessage CreateRequestMessage(RequestData requestDat
144144 if ( data != null )
145145 {
146146 var stream = requestData . MemoryStreamFactory . Create ( ) ;
147-
147+ requestMessage . Content = new StreamContent ( stream ) ;
148148 if ( requestData . HttpCompression )
149149 {
150- using ( var zipStream = new GZipStream ( stream , CompressionMode . Compress ) )
151- data . Write ( zipStream , requestData . ConnectionSettings ) ;
152-
153- requestMessage . Headers . Add ( "Content-Encoding" , "gzip" ) ;
150+ requestMessage . Content . Headers . Add ( "Content-Encoding" , "gzip" ) ;
154151 requestMessage . Headers . AcceptEncoding . Add ( new StringWithQualityHeaderValue ( "gzip" ) ) ;
155152 requestMessage . Headers . AcceptEncoding . Add ( new StringWithQualityHeaderValue ( "deflate" ) ) ;
153+ using ( var zipStream = new GZipStream ( stream , CompressionMode . Compress , true ) )
154+ data . Write ( zipStream , requestData . ConnectionSettings ) ;
156155 }
157156 else
158157 data . Write ( stream , requestData . ConnectionSettings ) ;
159-
160158 stream . Position = 0 ;
161- requestMessage . Content = new StreamContent ( stream ) ;
162159 }
163160 else
164161 {
165162 // Set content in order to set a Content-Type header.
166163 // Content gets diposed so can't be shared instance
167164 requestMessage . Content = new ByteArrayContent ( new byte [ 0 ] ) ;
168165 }
166+
169167 requestMessage . Content . Headers . ContentType = new MediaTypeHeaderValue ( requestData . ContentType ) ;
168+
170169 return requestMessage ;
171170 }
172171
Original file line number Diff line number Diff line change 1+ using FluentAssertions ;
2+ using Nest ;
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
6+ using System . Text ;
7+ using System . Threading . Tasks ;
8+ using Tests . Framework ;
9+ using Tests . Framework . Integration ;
10+ using Tests . Framework . MockData ;
11+ using Xunit ;
12+
13+ namespace Tests . ClientConcepts . Connection
14+ {
15+ [ Collection ( IntegrationContext . ReadOnly ) ]
16+ public class HttpConnectionTests
17+ {
18+ ReadOnlyCluster _cluster ;
19+
20+ public HttpConnectionTests ( ReadOnlyCluster cluster , EndpointUsage usage )
21+ {
22+ _cluster = cluster ;
23+ }
24+
25+ [ I ]
26+ public void HttpCompression ( )
27+ {
28+ var client = _cluster . Client ( s => s . EnableHttpCompression ( ) ) ;
29+ var response = client . Search < Project > ( s => s
30+ . Index ( "project" )
31+ . Query ( q => q
32+ . Term ( "foo" , "bar" )
33+ )
34+ ) ;
35+ response . IsValid . Should ( ) . BeTrue ( ) ;
36+ }
37+ }
38+ }
Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ bool shieldEnabled
135135 $ "es.path.repo={ this . RepositoryPath } ",
136136 $ "es.script.inline=on",
137137 $ "es.script.indexed=on",
138+ $ "es.http.compression=true",
138139 $ "es.node.{ attr } testingcluster=true",
139140 $ "es.shield.enabled=" + ( shieldEnabled ? "true" : "false" )
140141 } ;
Original file line number Diff line number Diff line change 541541 <Compile Include =" ClientConcepts\ConnectionPooling\RequestOverrides\RequestTimeoutsOverrides.doc.cs" />
542542 <Compile Include =" ClientConcepts\ConnectionPooling\RequestOverrides\RespectsAllowedStatusCode.doc.cs" />
543543 <Compile Include =" ClientConcepts\ConnectionPooling\RequestOverrides\RespectsForceNode.doc.cs" />
544+ <Compile Include =" ClientConcepts\Connection\HttpConnectionTests.cs" />
544545 <Compile Include =" ClientConcepts\HighLevel\Caching\FieldResolverCacheTests.cs" />
545546 <Compile Include =" ClientConcepts\HighLevel\Inference\DocumentPaths.doc.cs" />
546547 <Compile Include =" ClientConcepts\HighLevel\Inference\FeaturesInference.doc.cs" />
You can’t perform that action at this time.
0 commit comments