Skip to content

Commit

Permalink
optimize parse body
Browse files Browse the repository at this point in the history
  • Loading branch information
shuxiao9058 committed Jul 22, 2023
1 parent 425ec08 commit 346eba9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tabnine-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,17 @@ TOKEN is used to disambiguate multiple requests in a single buffer.
Return body, http-status, http-msg and error in list."
(when (buffer-live-p response-buffer)
(with-current-buffer response-buffer
(let* ((http-msg (progn (goto-char (point-min))
(while (looking-at "^HTTP/[.0-9]+ +[0-9]+ Connection established")
(forward-line 2))
(re-search-forward "HTTP/[.0-9]+ +[0-9]+" nil t) ;; jump to HTTP status line
(string-trim
(buffer-substring
(line-beginning-position)
(line-end-position)))))
(let* ((http-msg (save-excursion
(goto-char (point-min))
(while (looking-at "^HTTP/[.0-9]+ +[0-9]+ Connection established")
(forward-line 2))
(re-search-forward "HTTP/[.0-9]+ +[0-9]+" nil t) ;; jump to HTTP status line
(string-trim
(buffer-substring
(line-beginning-position)
(line-end-position)))))
(start (save-excursion
(goto-char (point-min))
(if (re-search-forward "^\{" nil t)
(line-beginning-position)
(forward-paragraph)
Expand Down Expand Up @@ -505,9 +507,9 @@ Return body, http-status, http-msg and error in list."
(t (unless (progn (goto-char (point-min))
(when (looking-at "^HTTP/[.0-9]+ +[0-9]+ Connection established")
(string-trim
(buffer-substring
(line-beginning-position)
(line-end-position)))))
(buffer-substring
(line-beginning-position)
(line-end-position)))))
(message "Unknow error: %s, buffer text: %s" http-msg (buffer-string)))
(list body http-status http-msg "unknow error")))))))

Expand Down

0 comments on commit 346eba9

Please sign in to comment.