Skip to content

Commit

Permalink
use userAgent of request if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Oct 8, 2024
1 parent 4f179f1 commit 1501c3a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ open class IppClient(val config: IppConfig = IppConfig()) {
sslSocketFactory = config.sslContext!!.socketFactory
if (!config.verifySSLHostname) hostnameVerifier = HostnameVerifier { _, _ -> true }
}
configure(chunked = request.hasDocument())
configure(
chunked = request.hasDocument(),
userAgent = request.httpUserAgent ?: config.userAgent
)
try {
request.write(outputStream)
val responseContentStream = try {
Expand Down Expand Up @@ -153,18 +156,18 @@ open class IppClient(val config: IppConfig = IppConfig()) {
}
}

private fun HttpURLConnection.configure(chunked: Boolean) {
private fun HttpURLConnection.configure(chunked: Boolean, userAgent: String?) {
config.run {
connectTimeout = timeout.toMillis().toInt()
readTimeout = timeout.toMillis().toInt()
userAgent?.let { setRequestProperty("User-Agent", it) }
if (password != null) setRequestProperty("Authorization", authorization())
}
doOutput = true // POST
if (chunked) setChunkedStreamingMode(0)
setRequestProperty("Content-Type", APPLICATION_IPP)
setRequestProperty("Accept", APPLICATION_IPP)
setRequestProperty("Accept-Encoding", "identity") // avoid 'gzip' with Androids OkHttp
userAgent?.let { setRequestProperty("User-Agent", it) }
}

private fun HttpURLConnection.validateHttpResponse(
Expand Down

0 comments on commit 1501c3a

Please sign in to comment.