Skip to content

Commit

Permalink
Merge pull request #2 from blake-watkins/allow-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
fjames86 committed Jan 18, 2024
2 parents 31fd07c + 280612d commit 8611ba5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
21 changes: 12 additions & 9 deletions ffi.lisp
Expand Up @@ -236,7 +236,9 @@



(defconstant +access-no-proxy+ 1)
(defconstant +access-no-proxy+ 1)
(defconstant +access-named-proxy+ 3)

;; HINTERNET WINAPI WinHttpOpen(
;; _In_opt_ LPCWSTR pwszUserAgent,
;; _In_ DWORD dwAccessType,
Expand All @@ -250,15 +252,16 @@
(proxy :pointer)
(bypass :pointer)
(flags :uint32))
(defun http-open (&optional user-agent)
(defun http-open (&optional user-agent proxy)
(with-wide-string (u (or user-agent "winhttp"))
(let ((h (%http-open u
+access-no-proxy+
(null-pointer)
(null-pointer)
0)))
(when (null-pointer-p h) (get-last-error))
h)))
(with-wide-string (p (or proxy ""))
(let ((h (%http-open u
(if proxy +access-named-proxy+ +access-no-proxy+)
(if proxy p (null-pointer))
(null-pointer)
0)))
(when (null-pointer-p h) (get-last-error))
h))))

;; BOOL WINAPI WinHttpCloseHandle(
;; _In_ HINTERNET hInternet
Expand Down
9 changes: 5 additions & 4 deletions util.lisp
Expand Up @@ -4,9 +4,9 @@

(in-package #:winhttp)

(defmacro with-http ((var &optional user-agent) &body body)
(defmacro with-http ((var &optional user-agent proxy) &body body)
"Evaluate body with VAR bound to a session handle."
`(let ((,var (http-open ,user-agent)))
`(let ((,var (http-open ,user-agent ,proxy)))
(unwind-protect (progn ,@body)
(close-handle ,var))))

Expand Down Expand Up @@ -184,7 +184,7 @@ babel may not be able to decode the text."
(defun http-request (url &key (method :get)
post-data (post-start 0) post-end
rawp headers timeout ignore-certificates-p
statuscb recv-buf (recv-start 0) recv-end)
statuscb recv-buf (recv-start 0) recv-end proxy)
"Send HTTP request to server.
URL ::= string in format [http|https://][username:password@]hostname[:port][/url]
METHOD ::= HTTP verb e.g. :GET, :POST etc
Expand All @@ -198,11 +198,12 @@ STATUSCB ::= if non-nil, is a symbol naming a callback defined using define-stat
This will be invoked to inform various status messages.
RECV-BUF ::= if provided, is an octet vector that receives the reply body.
If not supplied a buffer is allocated. Uses region bounded by RECV-START and RECV-END.
PROXY ::= NAME:PORT of proxy server to use ie 127.0.0.1:8080 or localhost:8080
Returns values return-data status-code headers content-length.
"

(let ((comp (crack-url url)))
(with-http (hsession)
(with-http (hsession nil proxy)
(when (eq (getf comp :scheme) :https)
(set-secure-protocols hsession :tls1 t :tls1-1 t :tls1-2 t))

Expand Down

0 comments on commit 8611ba5

Please sign in to comment.