aboutsummaryrefslogtreecommitdiff
path: root/sx-request.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-11 08:59:01 -0500
committerSean Allred <code@seanallred.com>2014-11-11 08:59:01 -0500
commit92d30aeee31c80238a4ce5a825806dadc0e3a065 (patch)
treef6b9c678adba38733de594b76a0e97253436299a /sx-request.el
parent5305686182f9e233d0c4d056eab9f28a40e3932c (diff)
parent94e649f7318b2518fe31af7cdea74b7f7bfde1e3 (diff)
Merge pull request #38 from vermiculus/gzip-testing
Proper GZIP testing
Diffstat (limited to 'sx-request.el')
-rw-r--r--sx-request.el29
1 files changed, 12 insertions, 17 deletions
diff --git a/sx-request.el b/sx-request.el
index 9d9dca4..56362fc 100644
--- a/sx-request.el
+++ b/sx-request.el
@@ -27,6 +27,7 @@
(require 'json)
(require 'sx)
+(require 'sx-encoding)
;;; Variables
@@ -92,24 +93,18 @@ number of requests left every time it finishes a call.")
(error "Response headers missing; response corrupt")
(delete-region (point-min) (point))
(buffer-string))))
- (response (ignore-errors
+ (response-zipped-p (sx-encoding-gzipped-p data))
+ (data (if (not response-zipped-p) data
+ (shell-command-on-region
+ (point-min) (point-max)
+ sx-request-unzip-program
+ nil t)
+ (buffer-string)))
+ (response (with-demoted-errors "`json' error: %S"
(json-read-from-string data))))
- ;; If the response isn't nil, the response was in plain text
- (unless response
- ;; try to decompress the response
- (setq response
- (with-demoted-errors "`json-read' error: %S"
- (shell-command-on-region
- (point-min) (point-max)
- sx-request-unzip-program
- nil t)
- (json-read-from-string
- (buffer-substring
- (point-min) (point-max)))))
- ;; if it still fails, error outline
- (unless response
- (sx-message "Unable to parse response: %S" response)
- (error "Response could not be read by `json-read-from-string'")))
+ (when (and (not response) (string-equal data "{}"))
+ (sx-message "Unable to parse response: %S" response)
+ (error "Response could not be read by `json-read-from-string'"))
;; If we get here, the response is a valid data structure
(sx-assoc-let response
(when error_id