Skip to content

Commit

Permalink
'twittering-get-response-...()' return "" or nil on failure.
Browse files Browse the repository at this point in the history
When the tail of HTTP header is not found in the given buffer,
'twittering-get-response-header()' returns an empty string and
'twittering-get-response-body()' returns nil.
  • Loading branch information
cvmat authored and hayamiz committed Dec 30, 2009
1 parent 28f89c5 commit 70fe5df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
@@ -1,4 +1,16 @@
<<<<<<< HEAD:ChangeLog
<<<<<<< HEAD:ChangeLog
=======
2009-12-30 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-get-response-header): On failure,
the function returns an empty string instead of the whole contents
of the buffer.
(twittering-get-response-body): When the function fails to find
the tail of header, it returns nil without trying to parse a
region.

>>>>>>> 'twittering-get-response-...()' return "" or nil on failure.:ChangeLog
2009-12-30 Satoshi Yatagawa <yata_github@y.hauN.org>

* twittering-mode.el (twittering-get-response-header): Correct a
Expand Down
22 changes: 10 additions & 12 deletions twittering-mode.el
Expand Up @@ -1136,11 +1136,9 @@ PARAMETERS is alist of URI parameters.
(when (search-forward-regexp
"HTTP/1\\.[01] 200 Connection established\r\n\r\n" nil t)
(delete-region (point-min) (point)))
(let* ((start (point))
(end (if (search-forward-regexp "\r?\n\r?\n" nil t)
(match-end 0)
(point-max))))
(buffer-substring start end))))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(buffer-substring (point-min) (match-end 0))
"")))

(defun twittering-get-response-body (buffer)
"Exract HTTP response body from HTTP response, parse it as XML, and return a
Expand All @@ -1150,13 +1148,13 @@ XML tree as list. Return nil when parse failed.
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(let ((start (if (search-forward-regexp "\r?\n\r?\n" nil t)
(match-end 0)
(point))))
(condition-case get-error ;; to guard when `xml-parse-region' failed.
(xml-parse-region start (point-max))
(error (message "Failure: %s" get-error)
nil)))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(let ((start (match-end 0)))
(condition-case get-error ;; to guard when `xml-parse-region' failed.
(xml-parse-region start (point-max))
(error (message "Failure: %s" get-error)
nil)))
nil)
))

(defun twittering-cache-status-datum (status-datum &optional data-var)
Expand Down

0 comments on commit 70fe5df

Please sign in to comment.