ringabout/httpx

IPv6 failed

Opened this issue · 0 comments

import options, asyncdispatch
import httpx, net

proc onRequest(req: Request): Future[void] {.async.} =
  # Log the incoming request
  echo "Received request: ", req.httpMethod.get(), " ", req.path

  if req.httpMethod == some(HttpGet):
    case req.path.get()
    of "/":
      req.send("Hello World")
      echo "Sent response: Hello World"
    else:
      req.send(Http404)
      echo "Sent response: 404 Not Found"

let settings = Settings(
  port: Port(80),
  bindAddr: "::",  # IPv6 address
  listener: newSocket(AF_INET6, SOCK_STREAM, IPPROTO_IPV6)
)

# Start the server and log that it's running
echo "Starting server on port ", settings.port
run(onRequest, settings)
echo "Server is running"

error

/Users/of/Work/Nim/web_test/ssr_test/src/serverv6.nim(22) serverv6
/Users/of/.choosenim/toolchains/nim-2.2.0/lib/pure/net.nim(309) newSocket
/Users/of/.choosenim/toolchains/nim-2.2.0/lib/std/oserrors.nim(92) raiseOSError
Error: unhandled exception: Bad file descriptor [OSError]