β What happened?
A bug occurred! π
http request fail when not using standard port.
π± Device Model
CMF Phone 2 Pro
π AxionOS Version
v2.6
π¦ Are you using GApps?
Yes
π Is your device rooted?
No
π Steps to Reproduce
- make a request to any site which use port other that 443 or 80. request instantly fails.
issue is here
return socket.use { s ->
val req = buildString {
append("${action.method} $path HTTP/1.1\r\n")
append("Host: $host\r\n")
append("Connection: close\r\n")
action.headers.forEach { (k, v) -> append("$k: $v\r\n") }
val bodyBytes = action.body?.toByteArray(Charsets.UTF_8)
if (bodyBytes != null) {
append("Content-Length: ${bodyBytes.size}\r\n")
}
append("\r\n")
if (action.body != null) append(action.body)
}
append("Host: $host\r\n")
it only pass host but ignore port address.
fix
val defaultPort = if (isHttps) 443 else 80
val hostHeader =
if (port == defaultPort) host
else "$host:$port"
return socket.use { s ->
val req = buildString {
append("${action.method} $path HTTP/1.1\r\n")
append("Host: $hostHeader\r\n")
append("Connection: close\r\n")
action.headers.forEach { (k, v) -> append("$k: $v\r\n") }
val bodyBytes = action.body?.toByteArray(Charsets.UTF_8)
if (bodyBytes != null) {
append("Content-Length: ${bodyBytes.size}\r\n")
}
append("\r\n")
if (action.body != null) append(action.body)
}
s.getOutputStream().apply {
write(req.toByteArray(Charsets.UTF_8))
flush()
}
val reader = BufferedReader(InputStreamReader(s.getInputStream()))
val statusLine = reader.readLine() ?: return@use -1
statusLine.split(" ", limit = 3).getOrNull(1)?.toIntOrNull() ?: -1
}
}
π Log Output
β
Verification Checklist
β What happened?
A bug occurred! π
http request fail when not using standard port.
π± Device Model
CMF Phone 2 Pro
π AxionOS Version
v2.6
π¦ Are you using GApps?
Yes
π Is your device rooted?
No
π Steps to Reproduce
issue is here
append("Host: $host\r\n")
it only pass host but ignore port address.
fix
π Log Output
β Verification Checklist