Skip to content

[Bug]: http request fail when not using standard port on routines.Β #240

@sujanbimali9

Description

@sujanbimali9

❗ 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

  1. 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

  • πŸ” I have searched for existing issues and found none related to this bug.
  • πŸ”„ I have reproduced the issue after a clean install without modifying system files.
  • βš™οΈ I have tested with different configurations (e.g., GApps/no GApps, rooted/non-rooted).
  • πŸ“Ž I have attached all necessary logs and provided reproduction steps.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions