gptel: Handle status HTTP 100
gptel.el (gptel--url-parse-response): Handle HTTP 100 followed by 200. Note: this fix is brittle, it will break if 100 is followed by an error code. gptel-curl.el (gptel-curl--stream-filter, gptel-curl--parse-stream): Ditto. Address #194.
This commit is contained in:
parent
a32f4effe5
commit
199595b0c8
2 changed files with 9 additions and 5 deletions
|
@ -201,7 +201,7 @@ PROCESS and _STATUS are process parameters."
|
||||||
(http-status (plist-get info :http-status))
|
(http-status (plist-get info :http-status))
|
||||||
(http-msg (plist-get info :status)))
|
(http-msg (plist-get info :status)))
|
||||||
(when gptel-log-level (gptel-curl--log-response proc-buf info)) ;logging
|
(when gptel-log-level (gptel-curl--log-response proc-buf info)) ;logging
|
||||||
(if (equal http-status "200") ;Finish handling response
|
(if (member http-status '("200" "100")) ;Finish handling response
|
||||||
(with-current-buffer gptel-buffer
|
(with-current-buffer gptel-buffer
|
||||||
(if (not tracking-marker) ;Empty response
|
(if (not tracking-marker) ;Empty response
|
||||||
(when gptel-mode (gptel--update-status " Empty response" 'success))
|
(when gptel-mode (gptel--update-status " Empty response" 'success))
|
||||||
|
@ -315,7 +315,7 @@ See `gptel--url-get-response' for details."
|
||||||
display-buffer-pop-up-window)
|
display-buffer-pop-up-window)
|
||||||
(reusable-frames . visible))))
|
(reusable-frames . visible))))
|
||||||
;; Run pre-response hook
|
;; Run pre-response hook
|
||||||
(when (and (equal (plist-get proc-info :http-status) "200")
|
(when (and (member (plist-get proc-info :http-status) '("200" "100"))
|
||||||
gptel-pre-response-hook)
|
gptel-pre-response-hook)
|
||||||
(with-current-buffer (marker-buffer (plist-get proc-info :position))
|
(with-current-buffer (marker-buffer (plist-get proc-info :position))
|
||||||
(run-hooks 'gptel-pre-response-hook))))
|
(run-hooks 'gptel-pre-response-hook))))
|
||||||
|
@ -323,7 +323,8 @@ See `gptel--url-get-response' for details."
|
||||||
(when-let ((http-msg (plist-get proc-info :status))
|
(when-let ((http-msg (plist-get proc-info :status))
|
||||||
(http-status (plist-get proc-info :http-status)))
|
(http-status (plist-get proc-info :http-status)))
|
||||||
;; Find data chunk(s) and run callback
|
;; Find data chunk(s) and run callback
|
||||||
(when-let (((equal http-status "200"))
|
;; FIXME Handle the case where HTTP 100 is followed by HTTP (not 200) BUG #194
|
||||||
|
(when-let (((member http-status '("200" "100")))
|
||||||
(response (funcall (plist-get proc-info :parser) nil proc-info))
|
(response (funcall (plist-get proc-info :parser) nil proc-info))
|
||||||
((not (equal response ""))))
|
((not (equal response ""))))
|
||||||
(funcall (or (plist-get proc-info :callback)
|
(funcall (or (plist-get proc-info :callback)
|
||||||
|
@ -385,7 +386,8 @@ PROC-INFO is a plist with contextual information."
|
||||||
(json-read)
|
(json-read)
|
||||||
(json-readtable-error 'json-read-error)))))
|
(json-readtable-error 'json-read-error)))))
|
||||||
(cond
|
(cond
|
||||||
((equal http-status "200")
|
;; FIXME Handle the case where HTTP 100 is followed by HTTP (not 200) BUG #194
|
||||||
|
((member http-status '("200" "100"))
|
||||||
(list (string-trim
|
(list (string-trim
|
||||||
(funcall parser nil response proc-info))
|
(funcall parser nil response proc-info))
|
||||||
http-msg))
|
http-msg))
|
||||||
|
|
4
gptel.el
4
gptel.el
|
@ -1183,7 +1183,9 @@ See `gptel-curl--get-response' for its contents.")
|
||||||
(json-read-from-string json-str)
|
(json-read-from-string json-str)
|
||||||
(json-readtable-error 'json-read-error))))))
|
(json-readtable-error 'json-read-error))))))
|
||||||
(cond
|
(cond
|
||||||
((or (= url-http-response-status 200) (string-match-p "200 OK" http-msg))
|
;; FIXME Handle the case where HTTP 100 is followed by HTTP (not 200) BUG #194
|
||||||
|
((or (memq url-http-response-status '(200 100))
|
||||||
|
(string-match-p "\\(?:1\\|2\\)00 OK" http-msg))
|
||||||
(list (string-trim (gptel--parse-response backend response
|
(list (string-trim (gptel--parse-response backend response
|
||||||
'(:buffer response-buffer)))
|
'(:buffer response-buffer)))
|
||||||
http-msg))
|
http-msg))
|
||||||
|
|
Loading…
Add table
Reference in a new issue