Skip to content

Commit 30f3469

Browse files
committed
Make chunking configurable
1 parent a957b5a commit 30f3469

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

acra-http/src/main/java/org/acra/config/HttpSenderConfiguration.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ class HttpSenderConfiguration(
127127
*/
128128
val compress: Boolean = false,
129129

130+
/**
131+
* if the request should be sent in chunks.
132+
* Set to true when using cronet.
133+
*
134+
* @since 5.11.3
135+
*/
136+
val chunked: Boolean = false,
137+
130138
/**
131139
* TLS versions supported by the server.
132140
*

acra-http/src/main/java/org/acra/http/BaseHttpRequest.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ import javax.net.ssl.TrustManagerFactory
4848
* @since 03.03.2017
4949
*/
5050
@Suppress("MemberVisibilityCanBePrivate")
51-
abstract class BaseHttpRequest<T>(private val config: CoreConfiguration, private val context: Context, private val method: HttpSender.Method,
52-
private val login: String?, private val password: String?, private val connectionTimeOut: Int, private val socketTimeOut: Int,
53-
private val headers: Map<String, String>?) : HttpRequest<T> {
51+
abstract class BaseHttpRequest<T>(
52+
private val config: CoreConfiguration, private val context: Context, private val method: HttpSender.Method,
53+
private val login: String?, private val password: String?, private val connectionTimeOut: Int, private val socketTimeOut: Int,
54+
private val headers: Map<String, String>?
55+
) : HttpRequest<T> {
5456
private val senderConfiguration: HttpSenderConfiguration = config.getPluginConfiguration()
5557

5658
/**
@@ -134,7 +136,9 @@ abstract class BaseHttpRequest<T>(private val config: CoreConfiguration, private
134136
// write output - see http://developer.android.com/reference/java/net/HttpURLConnection.html
135137
connection.requestMethod = method.name
136138
connection.doOutput = true
137-
connection.setChunkedStreamingMode(ACRAConstants.DEFAULT_BUFFER_SIZE_IN_BYTES)
139+
if (senderConfiguration.chunked) {
140+
connection.setChunkedStreamingMode(ACRAConstants.DEFAULT_BUFFER_SIZE_IN_BYTES)
141+
}
138142

139143
// Disable ConnectionPooling because otherwise OkHttp ConnectionPool will try to start a Thread on #connect
140144
System.setProperty("http.keepAlive", "false")
@@ -151,19 +155,19 @@ abstract class BaseHttpRequest<T>(private val config: CoreConfiguration, private
151155

152156
@Throws(IOException::class)
153157
protected fun handleResponse(responseCode: Int, responseMessage: String) {
154-
debug { "Request response : $responseCode : $responseMessage" }
158+
debug { "Request response : $responseCode : $responseMessage" }
155159
if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_MULT_CHOICE) {
156160
// All is good
157-
info { "Request received by server" }
161+
info { "Request received by server" }
158162
} else if (responseCode == HttpURLConnection.HTTP_CLIENT_TIMEOUT || responseCode >= HttpURLConnection.HTTP_INTERNAL_ERROR) {
159163
//timeout or server error. Repeat the request later.
160-
warn { "Could not send ACRA Post responseCode=$responseCode message=$responseMessage" }
164+
warn { "Could not send ACRA Post responseCode=$responseCode message=$responseMessage" }
161165
throw IOException("Host returned error code $responseCode")
162166
} else if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
163167
// Client error. The request must not be repeated. Discard it.
164-
warn { "$responseCode: Client error - request will be discarded" }
168+
warn { "$responseCode: Client error - request will be discarded" }
165169
} else {
166-
warn { "Could not send ACRA Post - request will be discarded. responseCode=$responseCode message=$responseMessage" }
170+
warn { "Could not send ACRA Post - request will be discarded. responseCode=$responseCode message=$responseMessage" }
167171
}
168172
}
169173

0 commit comments

Comments
 (0)