@@ -6,6 +6,7 @@ import io.mockk.every
6
6
import io.mockk.mockk
7
7
import io.mockk.spyk
8
8
import org.junit.jupiter.api.Assertions.assertEquals
9
+ import org.junit.jupiter.api.Assertions.assertFalse
9
10
import org.junit.jupiter.api.Assertions.assertTrue
10
11
import org.junit.jupiter.api.Assertions.fail
11
12
import org.junit.jupiter.api.Test
@@ -18,6 +19,7 @@ import java.net.HttpURLConnection
18
19
import java.net.MalformedURLException
19
20
import java.net.URL
20
21
import java.net.http.HttpClient
22
+ import java.util.zip.GZIPOutputStream
21
23
22
24
@TestInstance(TestInstance .Lifecycle .PER_CLASS )
23
25
class HTTPClientTests {
@@ -45,7 +47,9 @@ class HTTPClientTests {
45
47
46
48
@Test
47
49
fun `settings connection has correct configuration` () {
48
- httpClient.upload(" api.segment.io/v1" ).connection.let {
50
+ httpClient.upload(" api.segment.io/v1" ).also {
51
+ assertTrue(it.outputStream is GZIPOutputStream )
52
+ }.connection.let {
49
53
assertEquals(
50
54
" https://api.segment.io/v1/b" ,
51
55
it.url.toString()
@@ -129,11 +133,28 @@ class HTTPClientTests {
129
133
)
130
134
}
131
135
132
- httpClient.upload(" api.segment.io/v1" ).connection.let {
136
+ httpClient.upload(" api.segment.io/v1" ).also {
137
+ assertFalse(it.outputStream is GZIPOutputStream )
138
+ }.connection.let {
133
139
assertEquals(
134
140
" https://api.test.com" ,
135
141
it.url.toString()
136
142
)
137
143
}
138
144
}
145
+
146
+ @Test
147
+ fun `custom requestFactory can remove gzip` () {
148
+ val httpClient = HTTPClient (" 123" , object : RequestFactory () {
149
+ override fun upload (apiHost : String ): HttpURLConnection {
150
+ val connection: HttpURLConnection = openConnection(" https://$apiHost /b" )
151
+ connection.setRequestProperty(" Content-Type" , " text/plain" )
152
+ connection.doOutput = true
153
+ connection.setChunkedStreamingMode(0 )
154
+ return connection
155
+ }
156
+ })
157
+
158
+ assertFalse(httpClient.upload(" api.segment.io/v1" ).outputStream is GZIPOutputStream )
159
+ }
139
160
}
0 commit comments