Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use quri instead of puri for URIs. #65

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions cookies.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ which can be used for cookie headers."
name (and (plusp (length value)) value)
(and expires (render-cookie-date expires))
path domain securep http-only-p))))

(defun normalize-cookie-domain (domain)
"Adds a dot at the beginning of the string DOMAIN unless there
is already one."
Expand All @@ -109,26 +109,26 @@ every domain name is considered acceptable."
(> (count #\. (normalize-cookie-domain domain) :test #'char=) 1)))

(defun cookie-domain-matches (domain uri)
"Checks if the domain DOMAIN \(a string) matches the \(PURI) URI URI."
(ends-with-p (normalize-cookie-domain (puri:uri-host uri))
"Checks if the domain DOMAIN \(a string) matches the \(QURI) URI URI."
(ends-with-p (normalize-cookie-domain (quri:uri-host uri))
(normalize-cookie-domain domain)))

(defun send-cookie-p (cookie uri force-ssl)
"Checks if the cookie COOKIE should be sent to the server
depending on the \(PURI) URI URI and the value of FORCE-SSL \(as
depending on the \(QURI) URI URI and the value of FORCE-SSL \(as
in HTTP-REQUEST)."
(and ;; check domain
(cookie-domain-matches (cookie-domain cookie) uri)
;; check path
(starts-with-p (or (puri:uri-path uri) "/") (cookie-path cookie))
(starts-with-p (or (quri:uri-path uri) "/") (cookie-path cookie))
;; check expiry date
(let ((expires (cookie-expires cookie)))
(or (null expires)
(> expires (get-universal-time))))
;; check if connection must be secure
;; check if connection must be secure
(or (null (cookie-securep cookie))
force-ssl
(eq (puri:uri-scheme uri) :https))))
(eq (quri:uri-scheme uri) :https))))

(defun check-cookie (cookie)
"Checks if the slots of the COOKIE object COOKIE have valid values
Expand Down Expand Up @@ -225,7 +225,7 @@ convenience function.
;; fails to parse some of the stuff you encounter in the wild; or we
;; could try to employ CL-PPCRE, but that'd add a new dependency
;; without making this code much cleaner
(handler-case
(handler-case
(let* ((last-space-pos
(or (position #\Space string :test #'char= :from-end t)
(cookie-date-parse-error "Can't parse cookie date ~S, no space found." string)))
Expand All @@ -247,7 +247,7 @@ convenience function.
(t (cookie-date-parse-error "Can't parse cookie date ~S, confused by ~S part."
string part))))
(cond ((null day)
(unless (setq day (safe-parse-integer part))
(unless (setq day (safe-parse-integer part))
(setq month (interpret-as-month part))))
((null month)
(setq month (interpret-as-month part)))))
Expand All @@ -269,7 +269,7 @@ cookie, the value of the cookie, and an attribute/value list for
the optional cookie parameters."
(let ((*current-error-message* (format nil "While parsing cookie header ~S:" string))
result)
(dolist (substring (split-set-cookie-string string))
(dolist (substring (split-set-cookie-string string))
(with-sequence-from-string (stream substring)
(let* ((name/value (read-name-value-pair stream :cookie-syntax t))
(parameters (read-name-value-pairs stream :value-required-p nil :cookie-syntax t)))
Expand All @@ -280,19 +280,19 @@ the optional cookie parameters."
"Returns a list of COOKIE objects corresponding to the
`Set-Cookie' header as found in HEADERS \(an alist as returned by
HTTP-REQUEST). Collects only cookies which match the domain of
the \(PURI) URI URI."
the \(QURI) URI URI."
(loop with set-cookie-header = (header-value :set-cookie headers)
with parsed-cookies = (and set-cookie-header (parse-set-cookie set-cookie-header))
for (name value parameters) in parsed-cookies
for expires = (parameter-value "expires" parameters)
for domain = (or (parameter-value "domain" parameters) (puri:uri-host uri))
for domain = (or (parameter-value "domain" parameters) (quri:uri-host uri))
when (and (valid-cookie-domain-p domain)
(cookie-domain-matches domain uri))
collect (make-instance 'cookie
:name name
:value value
:path (or (parameter-value "path" parameters)
(puri:uri-path uri)
(quri:uri-path uri)
"/")
:expires (and expires
(plusp (length expires))
Expand Down
18 changes: 10 additions & 8 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h3 xmlns=""><a class="none" name="contents">Contents</a></h3>
</li>
<li><a href="#index">Symbol index</a></li>
</ol>

<h3 xmlns=""><a class="none" name="examples">Examples</a></h3>

<style type="text/css">
Expand Down Expand Up @@ -244,14 +244,14 @@ <h4 xmlns=""><a name="ex-binary-data">Requesting binary data</a></h4>
X-RateLimit-Limit: 60
Content-Length: 23
X-Content-Type-Options: nosniff
Cache-Control:
Cache-Control:
</span>
<span class="repl-output">#(123 34 109 101 115 115 97 103 101 34 58 34 78 111 116 32 70 111 117 110 100 34 125)
404
((:SERVER . "nginx") (:DATE . "Fri, 28 Dec 2012 08:37:31 GMT") (:CONTENT-TYPE . "application/json; charset=utf-8")
(:CONNECTION . "close") (:STATUS . "404 Not Found") (:X-GITHUB-MEDIA-TYPE . "github.beta") (:X-RATELIMIT-REMAINING . "48")
(:X-RATELIMIT-LIMIT . "60") (:CONTENT-LENGTH . "23") (:X-CONTENT-TYPE-OPTIONS . "nosniff") (:CACHE-CONTROL . ""))
#&lt;PURI:URI https://api.github.com/repos/edicl/drakma/git/tags/tag-does-not-exist&gt;
#&lt;QURI:URI https://api.github.com/repos/edicl/drakma/git/tags/tag-does-not-exist&gt;
#&lt;FLEXI-STREAMS:FLEXI-IO-STREAM {101C40C043}&gt;
T
"Not Found"</span>
Expand Down Expand Up @@ -343,7 +343,7 @@ <h4 xmlns=""><a name="ex-post-and-cookie">Posting data and using cookies</a></h4
</span>
<span class="headers-in">HTTP/1.1 200 OK
Date: Sun, 09 Dec 2012 08:25:13 GMT
Server:
Server:
X-Powered-By: PHP/5.2.17
<b>Set-Cookie: PHPSESSID=vijk3706eojs7n8u5cdpi3ju05; path=/</b>
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Expand All @@ -363,7 +363,7 @@ <h4 xmlns=""><a name="ex-post-and-cookie">Posting data and using cookies</a></h4
</span>
<span class="headers-in">HTTP/1.1 200 OK
Date: Sun, 09 Dec 2012 08:25:16 GMT
Server:
Server:
X-Powered-By: PHP/5.2.17
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expand Down Expand Up @@ -722,8 +722,10 @@ <h4 xmlns=""><a name="dict-request">Requests</a></h4>
Sends an <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a>
request to a web server and returns its reply.
<code xmlns=""><i>uri</i></code> is where the request is sent to,
and it is either a string denoting a uniform resource
identifier or a <code>PURI:URI</code> object. The scheme
and it is a string denoting a uniform resource
identifier, a <code>QURI:URI</code> object, or a
<code>PURI:URI</code> object. Support for <code>PURI:URI</code>
is deprecated. The scheme
of <code xmlns=""><i>uri</i></code> must be `http' or `https'.
The function returns SEVEN values - the body of the
reply<sup>0</sup> (but see below), the status
Expand Down Expand Up @@ -1405,7 +1407,7 @@ <h4 xmlns=""><a name="cookies">Cookies</a></h4>
page</a> for the <code>HttpOnly</code> extension).
</p>
<pre xmlns="http://www.w3.org/1999/xhtml"><span class="repl-output">? </span><span class="repl-input">(make-instance 'drakma:cookie
:name "Foo"
:name "Foo"
:value "Bar"
:expires (+ (get-universal-time) 3600)
:domain ".weitz.de")</span>
Expand Down
18 changes: 10 additions & 8 deletions doc/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<clix:chapter name='contents' title='Contents'></clix:chapter>
<clix:contents></clix:contents>

<clix:chapter name='examples' title='Examples'>

<style type="text/css">
Expand Down Expand Up @@ -211,14 +211,14 @@ X-RateLimit-Remaining: 48
X-RateLimit-Limit: 60
Content-Length: 23
X-Content-Type-Options: nosniff
Cache-Control:
Cache-Control:
</span>
<span class="repl-output">#(123 34 109 101 115 115 97 103 101 34 58 34 78 111 116 32 70 111 117 110 100 34 125)
404
((:SERVER . "nginx") (:DATE . "Fri, 28 Dec 2012 08:37:31 GMT") (:CONTENT-TYPE . "application/json; charset=utf-8")
(:CONNECTION . "close") (:STATUS . "404 Not Found") (:X-GITHUB-MEDIA-TYPE . "github.beta") (:X-RATELIMIT-REMAINING . "48")
(:X-RATELIMIT-LIMIT . "60") (:CONTENT-LENGTH . "23") (:X-CONTENT-TYPE-OPTIONS . "nosniff") (:CACHE-CONTROL . ""))
#&lt;PURI:URI https://api.github.com/repos/edicl/drakma/git/tags/tag-does-not-exist&gt;
#&lt;QURI:URI https://api.github.com/repos/edicl/drakma/git/tags/tag-does-not-exist&gt;
#&lt;FLEXI-STREAMS:FLEXI-IO-STREAM {101C40C043}&gt;
T
"Not Found"</span>
Expand Down Expand Up @@ -311,7 +311,7 @@ Content-Length: 40
</span>
<span class="headers-in">HTTP/1.1 200 OK
Date: Sun, 09 Dec 2012 08:25:13 GMT
Server:
Server:
X-Powered-By: PHP/5.2.17
<b>Set-Cookie: PHPSESSID=vijk3706eojs7n8u5cdpi3ju05; path=/</b>
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Expand All @@ -331,7 +331,7 @@ Connection: close
</span>
<span class="headers-in">HTTP/1.1 200 OK
Date: Sun, 09 Dec 2012 08:25:16 GMT
Server:
Server:
X-Powered-By: PHP/5.2.17
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expand Down Expand Up @@ -701,8 +701,10 @@ T</span>
href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a>
request to a web server and returns its reply.
<clix:arg>uri</clix:arg> is where the request is sent to,
and it is either a string denoting a uniform resource
identifier or a <code>PURI:URI</code> object. The scheme
and it is a string denoting a uniform resource
identifier, a <code>QURI:URI</code> object, or a
<code>PURI:URI</code> object. Support for <code>PURI:URI</code>
is deprecated. The scheme
of <clix:arg>uri</clix:arg> must be `http' or `https'.
The function returns SEVEN values - the body of the
reply<sup>0</sup> (but see below), the status
Expand Down Expand Up @@ -1401,7 +1403,7 @@ T</span>
page</a> for the <code>HttpOnly</code> extension).
</p>
<pre><span class="repl-output">? </span><span class="repl-input">(make-instance 'drakma:cookie
:name "Foo"
:name "Foo"
:value "Bar"
:expires (+ (get-universal-time) 3600)
:domain ".weitz.de")</span>
Expand Down
3 changes: 2 additions & 1 deletion drakma.asd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
(:file "cookies")
(:file "encoding")
(:file "request"))
:depends-on (:puri
:depends-on (:quri
:puri ; For backwards compatibility
:cl-base64
:chunga
:flexi-streams
Expand Down
1 change: 1 addition & 0 deletions packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#:*header-stream*
#:*ignore-unparseable-cookie-dates-p*
#:*text-content-types*
#:*return-puri-uri*
#:cookie
#:cookie-error
#:cookie-error-cookie
Expand Down
Loading