summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorRyan Marcus <ryan@rmarcus.info>2016-07-27 17:26:11 -0400
committerRyan Marcus <ryan@rmarcus.info>2016-07-27 17:26:11 -0400
commit0ada2aedfafbe489f9f73b8b622804f6d1c0ed7a (patch)
tree92556aea91692d992dcb39a567ca232fd48eebcf /lib/pure
parent0a03b18ae97d3a484c1daf362e2b1f8208d06a8d (diff)
downloadNim-0ada2aedfafbe489f9f73b8b622804f6d1c0ed7a.tar.gz
added when() block so that the compiler doesn't try to link SSL methods when SSL isn't available
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/httpclient.nim45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 6aab8ed3d..8b4aafc81 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -418,28 +418,31 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
   # send the appropiate CONNECT header. If not, simply connect to the proper
   # host (which may still be the proxy, for normal HTTP)
   if proxy != nil and hostUrl.scheme == "https":
-    var connectHeaders = "CONNECT "
-    let targetPort = if hostUrl.port == "": 443 else: hostUrl.port.parseInt
-    connectHeaders.add(hostUrl.hostname)
-    connectHeaders.add(":" & $targetPort)
-    connectHeaders.add(" HTTP/1.1\c\L")
-    connectHeaders.add("Host: " & hostUrl.hostname & ":" & $targetPort & "\c\L")
-    if proxy.auth != "":
-      let auth = base64.encode(proxy.auth, newline = "")
-      connectHeaders.add("Proxy-Authorization: basic " & auth & "\c\L")
-    connectHeaders.add("\c\L")
-    if timeout == -1:
-      s.connect(r.hostname, port)
-    else:
-      s.connect(r.hostname, port, timeout)
+    when defined(ssl):
+      var connectHeaders = "CONNECT "
+      let targetPort = if hostUrl.port == "": 443 else: hostUrl.port.parseInt
+      connectHeaders.add(hostUrl.hostname)
+      connectHeaders.add(":" & $targetPort)
+      connectHeaders.add(" HTTP/1.1\c\L")
+      connectHeaders.add("Host: " & hostUrl.hostname & ":" & $targetPort & "\c\L")
+      if proxy.auth != "":
+        let auth = base64.encode(proxy.auth, newline = "")
+        connectHeaders.add("Proxy-Authorization: basic " & auth & "\c\L")
+      connectHeaders.add("\c\L")
+      if timeout == -1:
+        s.connect(r.hostname, port)
+      else:
+        s.connect(r.hostname, port, timeout)
 
-    s.send(connectHeaders)
-    let connectResult = parseResponse(s, false, timeout)
-    if not connectResult.status.startsWith("200"):
-      raise newException(HttpRequestError,
-                         "The proxy server rejected a CONNECT request, " &
-                         "so a secure connection could not be established.")
-    sslContext.wrapConnectedSocket(s, handshakeAsClient)
+      s.send(connectHeaders)
+      let connectResult = parseResponse(s, false, timeout)
+      if not connectResult.status.startsWith("200"):
+        raise newException(HttpRequestError,
+                           "The proxy server rejected a CONNECT request, " &
+                           "so a secure connection could not be established.")
+      sslContext.wrapConnectedSocket(s, handshakeAsClient)
+    else:
+      raise newException(HttpRequestError, "SSL support not available. Cannot connect via proxy over SSL")
   else:
     if timeout == -1:
       s.connect(r.hostname, port)