Skip to content

Commit

Permalink
Merge pull request #43 from peoplestom/master
Browse files Browse the repository at this point in the history
Properly fixed parsing HEAD responses.
  • Loading branch information
fukamachi committed Nov 28, 2023
2 parents 363d384 + fe083bc commit 2232fc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/fast-http.lisp
Expand Up @@ -100,7 +100,7 @@
:invalid-parameter-value))
(in-package :fast-http)

(defun-careful make-parser (http &key first-line-callback header-callback body-callback finish-callback)
(defun-careful make-parser (http &key first-line-callback header-callback body-callback finish-callback (head-request nil))
(declare (type http http))
(let (callbacks

Expand Down Expand Up @@ -217,7 +217,7 @@
end nil))
(setf (http-mark http) start)
(handler-case
(funcall parse-fn http callbacks (the simple-byte-vector data) :start start :end end)
(funcall parse-fn http callbacks (the simple-byte-vector data) :start start :end end :head-request head-request)
(eof ()
(setq data-buffer
(subseq data (http-mark http) (or end (length data)))))))))
Expand Down
14 changes: 10 additions & 4 deletions src/parser.lisp
Expand Up @@ -474,7 +474,7 @@ us a never-ending header that the application keeps buffering.")
(decf (http-content-length http) readable-count)
(callback-data :body http callbacks data start end)
(setf (http-mark http) end)
(values end (= readable-count 0))))))
(values end nil)))))

(defun-speedy http-message-needs-eof-p (http)
(let ((status-code (http-status http)))
Expand Down Expand Up @@ -622,9 +622,10 @@ us a never-ending header that the application keeps buffering.")
(callback-notify :message-complete http callbacks)))))
(error 'eof)))

(defun-speedy parse-request (http callbacks data &key (start 0) end)
(defun-speedy parse-request (http callbacks data &key (start 0) end (head-request nil))
(declare (type http http)
(type simple-byte-vector data))
(type simple-byte-vector data)
(ignore head-request))
(let ((end (or end (length data))))
(declare (type pointer start end))
(handler-bind ((match-failed
Expand Down Expand Up @@ -727,7 +728,7 @@ us a never-ending header that the application keeps buffering.")
(return-from parse-request (pos)))))
(error 'eof)))

(defun-speedy parse-response (http callbacks data &key (start 0) end)
(defun-speedy parse-response (http callbacks data &key (start 0) end (head-request nil))
(declare (type http http)
(type simple-byte-vector data))
(let ((end (or end
Expand Down Expand Up @@ -785,6 +786,11 @@ us a never-ending header that the application keeps buffering.")
+state-chunk-size+
+state-body+))

(when head-request
(callback-notify :message-complete http callbacks)
(setf (http-state http) +state-first-line+)
(return-from parse-response (pos)))

body
(if (http-chunked-p http)
(advance-to* (parse-chunked-body http callbacks data (pos) end))
Expand Down

0 comments on commit 2232fc9

Please sign in to comment.