diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-04 21:10:46 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-04 21:10:46 +0100 |
| commit | 74a130c90a97da3bdf1352a4f95f2f85be315923 (patch) | |
| tree | 191350c0b6f8ff394087edf183f8f021979fa710 | |
| parent | a15d056b496587224ebca8e198749f2848e89782 (diff) | |
| download | chawan-74a130c90a97da3bdf1352a4f95f2f85be315923.tar.gz | |
gopher: move ipv6 handling to lcgi
| -rw-r--r-- | adapter/protocol/gopher.nim | 10 | ||||
| -rw-r--r-- | adapter/protocol/lcgi.nim | 18 |
2 files changed, 18 insertions, 10 deletions
diff --git a/adapter/protocol/gopher.nim b/adapter/protocol/gopher.nim index 218e2da4..42f2f898 100644 --- a/adapter/protocol/gopher.nim +++ b/adapter/protocol/gopher.nim @@ -1,4 +1,3 @@ -import std/options import std/os import std/posix import std/strutils @@ -54,13 +53,8 @@ proc main() = if getEnv("REQUEST_METHOD") != "GET": os.die("InvalidMethod") let scheme = getEnv("MAPPED_URI_SCHEME") - var host = getEnv("MAPPED_URI_HOST") - if host == "": - os.die("InvalidURL missing hostname") - if host[0] == '[' and host[^1] == ']': - host.delete(0..0) - host.setLen(host.high) - let port = $parseInt32(getEnv("MAPPED_URI_PORT")).get(70) + let host = getEnv("MAPPED_URI_HOST") + let port = getEnvEmpty("MAPPED_URI_PORT", "70") let query = getEnv("MAPPED_URI_QUERY").after('=') var path = getEnv("MAPPED_URI_PATH") var i = 0 diff --git a/adapter/protocol/lcgi.nim b/adapter/protocol/lcgi.nim index 5a7bf718..0313c836 100644 --- a/adapter/protocol/lcgi.nim +++ b/adapter/protocol/lcgi.nim @@ -172,9 +172,16 @@ proc connectProxySocket(os: PosixStream; host, port, proxy: string; pass = auth.after(':') i = authi + 1 var proxyHost = "" - while i < proxy.len and proxy[i] notin {':', '/'}: - proxyHost &= proxy[i] + if i < proxy.len and proxy[i] == '[': inc i + while i < proxy.len and proxy[i] != ']': + proxyHost &= proxy[i] + inc i + inc i + else: + while i < proxy.len and proxy[i] notin {':', '/'}: + proxyHost &= proxy[i] + inc i inc i var proxyPort = "" while i < proxy.len and proxy[i] in AsciiDigit: @@ -193,6 +200,13 @@ proc connectProxySocket(os: PosixStream; host, port, proxy: string; # In case we connect to a proxy, only the target matters. proc connectSocket*(os: PosixStream; host, port: string; outIpv6: var bool): PosixStream = + if host.len == 0: + os.die("InvalidURL", "missing hostname") + var host = host + if host.len > 0 and host[0] == '[' and host[^1] == ']': + #TODO set outIpv6? + host.delete(0..0) + host.setLen(host.high) let proxy = getEnv("ALL_PROXY") if proxy != "": return os.connectProxySocket(host, port, proxy, outIpv6) |