I spent some trying to understand this bug but:
    
    
    proc newConnection(client: HttpClient | AsyncHttpClient,
                       url: Uri) {.multisync.} =
      if client.currentURL.hostname != url.hostname or
          client.currentURL.scheme != url.scheme or
          client.currentURL.port != url.port or
          (not client.connected):
        # Connect to proxy if specified
        let connectionUrl =
          if client.proxy.isNil: url else: client.proxy.url
        
        echo("newConnection LOGS:")
        echo($(client.proxy.isNil))
        echo("URL:" & repr(url))
        echo("PURL:" & repr(client.proxy.url))
        echo("CU/A: " & repr($connectionUrl))
        
        let isSsl = connectionUrl.scheme.toLowerAscii() == "https"
        
        if isSsl and not defined(ssl):
          raise newException(HttpRequestError,
            "SSL support is not available. Cannot connect over SSL. Compile 
with -d:ssl to enable.")
        
        if client.connected:
          client.close()
          client.connected = false
        echo("CU/B: " & repr($connectionUrl))
        
        # TODO: I should be able to write 'net.Port' here...
        if connectionUrl.port == "":
          echo("PORT IS EMPTY!")
          echo("CU/C: " & repr($connectionUrl))
          echo(repr(connectionUrl.port))
          echo($(connectionUrl.port == ""))
        let port =
          if connectionUrl.port == "":
            if isSsl:
              nativesockets.Port(443)
            else:
              nativesockets.Port(80)
          else: nativesockets.Port(connectionUrl.port.parseInt)
        
        when client is HttpClient:
          echo("httpclient.nim/newConnection/when")
          echo("CU:" & repr(connectionUrl))
          echo("HN:" & repr(connectionUrl.hostname))
          echo("PortEmpty:", connectionUrl.port == "")
          echo("Port:" & repr(port))
          echo("CU path:" & repr(connectionUrl.path))
          client.socket = await net.dial(connectionUrl.hostname, port)
        elif client is AsyncHttpClient:
          client.socket = await asyncnet.dial(connectionUrl.hostname, port)
        else: {.fatal: "Unsupported client type".}
    
    
    Run

and still nonsense:
    
    
    newConnection LOGS:
    false
    URL:[scheme = 0x7f8d2dce1b20"http", username = "", password = "", hostname 
= 0x7f8d2dcbccb8"nim-lang.org", port = "", path = 
0x7f8d2dcc7bf0"/docs/httpclient.html", query = "", anchor = "", opaque = false]
    
    PURL:[scheme = "", username = "", password = "", hostname = "", port = "",
    path = 0x7f8d2dcda058"(scheme: \"http\", username: \"\", password: \"\", 
hostname: \"$THE_RIGHT_PROXY_IP\",
    port: \"8080\", path: \"\", query: \"\", anchor: \"\", opaque: false)",
    query = "", anchor = "", opaque = false]
    
    CU/A: 0x7f8d2dcda1a8"(scheme: \"http\", username: \"\", password: \"\", 
hostname: \"$THE_RIGHT_PROXY_IP\", p
    ort: \"8080\", path: \"\", query: \"\", anchor: \"\", opaque: false)"
    CU/B: 0x7f8d2dcda250"(scheme: \"http\", username: \"\", password: \"\", 
hostname: \"$THE_RIGHT_PROXY_IP\", p
    ort: \"8080\", path: \"\", query: \"\", anchor: \"\", opaque: false)"
    PORT IS EMPTY!
    CU/C: 0x7f8d2dcda2f8"(scheme: \"http\", username: \"\", password: \"\", 
hostname: \"$THE_RIGHT_PROXY_IP\", p
    ort: \"8080\", path: \"\", query: \"\", anchor: \"\", opaque: false)"
    ""
    true
    httpclient.nim/newConnection/when
    CU:[scheme = "", username = "", password = "", hostname = "", port = "",
    path = 0x7f8d2dcda058"(scheme: \"http\", username: \"\", password: \"\", 
hostname: \"$THE_RIGHT_PROXY_IP\",
    port: \"8080\", path: \"\", query: \"\", anchor: \"\", opaque: false)",
    query = "", anchor = "", opaque = false]
    
    HN:""
    PortEmpty:true
    Port:80
    CU path:0x7f8d2dcda058"(scheme: \"http\", username: \"\", password: \"\", 
hostname: \"$THE_RIGHT_PROXY_IP\",
     port: \"8080\", path: \"\", query: \"\", anchor: \"\", opaque: false)"
    
    
    
    Run

Reply via email to