File tree 3 files changed +45
-7
lines changed
Elasticsearch.Net/Connection
ClientConcepts/Connection
3 files changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -141,29 +141,28 @@ protected virtual HttpRequestMessage CreateRequestMessage(RequestData requestDat
141
141
if ( data != null )
142
142
{
143
143
var stream = requestData . MemoryStreamFactory . Create ( ) ;
144
-
144
+ requestMessage . Content = new StreamContent ( stream ) ;
145
145
if ( requestData . HttpCompression )
146
146
{
147
- using ( var zipStream = new GZipStream ( stream , CompressionMode . Compress ) )
148
- data . Write ( zipStream , requestData . ConnectionSettings ) ;
149
-
150
- requestMessage . Headers . Add ( "Content-Encoding" , "gzip" ) ;
147
+ requestMessage . Content . Headers . Add ( "Content-Encoding" , "gzip" ) ;
151
148
requestMessage . Headers . AcceptEncoding . Add ( new StringWithQualityHeaderValue ( "gzip" ) ) ;
152
149
requestMessage . Headers . AcceptEncoding . Add ( new StringWithQualityHeaderValue ( "deflate" ) ) ;
150
+ using ( var zipStream = new GZipStream ( stream , CompressionMode . Compress , true ) )
151
+ data . Write ( zipStream , requestData . ConnectionSettings ) ;
153
152
}
154
153
else
155
154
data . Write ( stream , requestData . ConnectionSettings ) ;
156
-
157
155
stream . Position = 0 ;
158
- requestMessage . Content = new StreamContent ( stream ) ;
159
156
}
160
157
else
161
158
{
162
159
// Set content in order to set a Content-Type header.
163
160
// Content gets diposed so can't be shared instance
164
161
requestMessage . Content = new ByteArrayContent ( new byte [ 0 ] ) ;
165
162
}
163
+
166
164
requestMessage . Content . Headers . ContentType = new MediaTypeHeaderValue ( requestData . ContentType ) ;
165
+
167
166
return requestMessage ;
168
167
}
169
168
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 ( TypeOfCluster . 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 554
554
<Compile Include =" ClientConcepts\ConnectionPooling\RequestOverrides\RequestTimeoutsOverrides.doc.cs" />
555
555
<Compile Include =" ClientConcepts\ConnectionPooling\RequestOverrides\RespectsAllowedStatusCode.doc.cs" />
556
556
<Compile Include =" ClientConcepts\ConnectionPooling\RequestOverrides\RespectsForceNode.doc.cs" />
557
+ <Compile Include =" ClientConcepts\Connection\HttpConnectionTests.cs" />
557
558
<Compile Include =" ClientConcepts\HighLevel\Inference\DocumentPaths.doc.cs" />
558
559
<Compile Include =" ClientConcepts\HighLevel\Inference\FeaturesInference.doc.cs" />
559
560
<Compile Include =" ClientConcepts\HighLevel\Inference\FieldInference.doc.cs" />
You can’t perform that action at this time.
0 commit comments