(defvar *http-use-tls* t)

(defun toggle-http-tls ()
  (setf *http-use-tls* (not *http-use-tls*)))

(defun get-http-port ()
  (if *http-use-tls* 443 8000))

(defun wifi-dial ()
  (wifi-connect *wifi-ssid* *wifi-password*))

(defun curl (host url)
  (let ((println #'(lambda (x s) (format s "~a~a~%" x #\return))))
    (with-client (s host (get-http-port))
		 (println (format nil "GET ~a HTTP/1.0" url) s)
		 (println (format nil "Host: ~a" host) s)
		 (println "Connection: close" s) 
		 (println "" s)
		 (loop (unless (zerop (available s)) (return)))
		 (loop
		   (delay 100)
		   (when (zerop (available s)) (return))
		   (princ (read-line s))
		   (terpri)))))

(defun nc-read (host port)
  (with-client (s host port)
	       (loop (unless (zerop (available s)) (return)))
	       (loop
		 (delay 100)
		 (when (zerop (available s)) (return))
		 (princ (read-line s))
		 (terpri))))

