InternetUtils: Honor content-type header

This commit is contained in:
José Rebelo
2026-04-19 09:55:08 +01:00
parent dd46ba54be
commit a948713fc4
@@ -172,7 +172,8 @@ class InternetUtils {
// Convert body string to RequestBody if allowed // Convert body string to RequestBody if allowed
val requestBody: RequestBody? = val requestBody: RequestBody? =
if (body != null && method.uppercase() !in listOf("GET", "HEAD")) { if (body != null && method.uppercase() !in listOf("GET", "HEAD")) {
body.toRequestBody("application/octet-stream".toMediaType()) val contentType = getHeader(requestHeaders, "content-type") ?: "application/octet-stream"
body.toRequestBody(contentType.toMediaType())
} else null } else null
// Configure HTTP method // Configure HTTP method
@@ -226,6 +227,16 @@ class InternetUtils {
return result return result
} }
private fun getHeader(headers: Map<String, String>, key: String): String? {
for (e in headers) {
if (e.key.equals(key, ignoreCase = true)) {
return e.value
}
}
return null
}
/** /**
* Creates an OkHttpClient that accepts all SSL certificates (insecure). * Creates an OkHttpClient that accepts all SSL certificates (insecure).
*/ */