From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: Translation of http status code to text
Date: Tue, 23 Mar 2010 10:02:24 -0500 [thread overview]
Message-ID: <87ocifxerj.fsf@lifelogs.com> (raw)
In-Reply-To: 877hp3ibft.fsf@mail.jurta.org
[-- Attachment #1: Type: text/plain, Size: 1913 bytes --]
On Tue, 23 Mar 2010 11:54:18 +0200 Juri Linkov <juri@jurta.org> wrote:
JL> Please don't add symbols. Developers prefer to refer to numbers.
I considered that but it really seemed useful to have symbolic codes as
I was working through the list of text explanations.
On Tue, 23 Mar 2010 11:54:40 +0100 joakim@verona.se wrote:
j> As a developer I'd like both numbers and symbols. Maybe thats just me. I
j> think this is a bit particular for the http protocol, since some codes
j> are extremely well known, whereas others are not.
Ditto.
On Tue, 23 Mar 2010 08:57:15 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
SM> I see, then it's OK to add symbols, I guess, but in this case use
SM> shorter ones, so you can do:
SM> (case (cadr (assq status-number url-http-codes)))
SM> (OK ...)
SM> (moved-permanently ...)
SM> (proxy-authentication-required ...)
SM> (accepted ...)
SM> ...)
Yeah, that was the other option. It works too.
SM> And in that case, a better option is to create the symbols
SM> programmatically from the error string:
SM> (defconst url-http-codes
SM> (mapcar (lambda (x)
SM> (let ((s (subst-char-in-string ?\s ?- (cadr x))))
SM> (when (string-match "-(.*)" s)
SM> (setq s (substring s 0 (match-beginning 0))))
SM> (list (car x) (intern (downcase s)) (cadr x))))
SM> '((100 "Continue with request")
SM> ...)))
From the perspective of the programmer it's better to see the symbols
(grep won't work with this approach). Also "OK" look weird as the "ok"
status code and "time-out" in the error code is odd IMHO. These are
matters of taste but I hope you'll allow that the manually generated
table is a little better. It only has to be done once, after all.
Attached is another attempt which uses the symbols in the code and
doesn't dynamically generate the symbols.
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: url-http-codes.patch --]
[-- Type: text/x-diff, Size: 11201 bytes --]
=== modified file 'lisp/url/url-http.el'
--- lisp/url/url-http.el 2010-01-13 08:35:10 +0000
+++ lisp/url/url-http.el 2010-03-23 14:54:14 +0000
@@ -64,6 +64,55 @@
nil will explicitly close the connection to the server after every
request.")
+(defconst url-http-codes
+ '((100 continue "Continue with request")
+ (101 switching-protocols "Switching protocols")
+ (102 processing "Processing (Added by DAV)")
+ (200 OK "OK")
+ (201 created "Created")
+ (202 accepted "Accepted")
+ (203 non-authoritative "Non-authoritative information")
+ (204 no-content "No content")
+ (205 reset-content "Reset content")
+ (206 partial-content "Partial content")
+ (207 multi-status "Multi-status (Added by DAV)")
+ (300 multiple-choices "Multiple choices")
+ (301 moved-permanently "Moved permanently")
+ (302 found "Found")
+ (303 see-other "See other")
+ (304 not-modified "Not modified")
+ (305 use-proxy "Use proxy")
+ (307 temporary-redirect "Temporary redirect")
+ (400 bad-request "Bad Request")
+ (401 unauthorized "Unauthorized")
+ (402 payment-required "Payment required")
+ (403 forbidden "Forbidden")
+ (404 not-found "Not found")
+ (405 method-not-allowed "Method not allowed")
+ (406 not-acceptable "Not acceptable")
+ (407 proxy-authentication-required "Proxy authentication required")
+ (408 request-timeout "Request time-out")
+ (409 conflict "Conflict")
+ (410 gone "Gone")
+ (411 length-required "Length required")
+ (412 precondition-failed "Precondition failed")
+ (413 request-entity-too-large "Request entity too large")
+ (414 request-uri-too-large "Request-URI too large")
+ (415 unsupported-media-type "Unsupported media type")
+ (416 requested-range-not-satisfiable "Requested range not satisfiable")
+ (417 expectation-failed "Expectation failed")
+ (422 unprocessable-entity "Unprocessable Entity (Added by DAV)")
+ (423 locked "Locked")
+ (424 failed-Dependency "Failed Dependency")
+ (500 internal-server-error "Internal server error")
+ (501 not-implemented "Not implemented")
+ (502 bad-gateway "Bad gateway")
+ (503 service-unavailable "Service unavailable")
+ (504 gateway-timeout "Gateway time-out")
+ (505 http-version-not-supported "HTTP version not supported")
+ (507 insufficient-storage "Insufficient storage")
+"The HTTP return codes and their text."))
+
;(eval-when-compile
;; These are all macros so that they are hidden from external sight
;; when the file is byte-compiled.
@@ -435,7 +484,9 @@
(delete-process url-http-process)))))
(let ((buffer (current-buffer))
(class nil)
- (success nil))
+ (success nil)
+ ;; other status symbols: jewelry and luxury cars
+ (status-symbol (cadr (assq status-number url-http-codes))))
(setq class (/ url-http-response-status 100))
(url-http-debug "Parsed HTTP headers: class=%d status=%d" class url-http-response-status)
(url-http-handle-cookies)
@@ -463,8 +514,8 @@
;; 205 Reset content
;; 206 Partial content
;; 207 Multi-status (Added by DAV)
- (case url-http-response-status
- ((204 205)
+ (case status-symbol
+ ((no-content reset-content)
;; No new data, just stay at the same document
(url-mark-buffer-as-dead buffer)
(setq success t))
@@ -485,8 +536,8 @@
;; 307 Temporary redirect
(let ((redirect-uri (or (mail-fetch-field "Location")
(mail-fetch-field "URI"))))
- (case url-http-response-status
- (300
+ (case status-symbol
+ (multiple-choices ; 300
;; Quoth the spec (section 10.3.1)
;; -------------------------------
;; The requested resource corresponds to any one of a set of
@@ -503,7 +554,7 @@
;; We do not support agent-driven negotiation, so we just
;; redirect to the preferred URI if one is provided.
nil)
- ((301 302 307)
+ ((moved-permanently found temporary-redirect) ; 301 302 307
;; If the 301|302 status code is received in response to a
;; request other than GET or HEAD, the user agent MUST NOT
;; automatically redirect the request unless it can be
@@ -519,20 +570,20 @@
url-http-method url-http-response-status)
(setq url-http-method "GET"
url-http-data nil)))
- (303
+ (see-other ; 303
;; The response to the request can be found under a different
;; URI and SHOULD be retrieved using a GET method on that
;; resource.
(setq url-http-method "GET"
url-http-data nil))
- (304
+ (not-modified ; 304
;; The 304 response MUST NOT contain a message-body.
(url-http-debug "Extracting document from cache... (%s)"
(url-cache-create-filename (url-view-url t)))
(url-cache-extract (url-cache-create-filename (url-view-url t)))
(setq redirect-uri nil
success t))
- (305
+ (use-proxy ; 305
;; The requested resource MUST be accessed through the
;; proxy given by the Location field. The Location field
;; gives the URI of the proxy. The recipient is expected
@@ -620,51 +671,51 @@
;; 422 Unprocessable Entity (Added by DAV)
;; 423 Locked
;; 424 Failed Dependency
- (case url-http-response-status
- (401
+ (case status-symbol
+ (unauthorized ; 401
;; The request requires user authentication. The response
;; MUST include a WWW-Authenticate header field containing a
;; challenge applicable to the requested resource. The
;; client MAY repeat the request with a suitable
;; Authorization header field.
(url-http-handle-authentication nil))
- (402
+ (payment-required ; 402
;; This code is reserved for future use
(url-mark-buffer-as-dead buffer)
(error "Somebody wants you to give them money"))
- (403
+ (forbidden ; 403
;; The server understood the request, but is refusing to
;; fulfill it. Authorization will not help and the request
;; SHOULD NOT be repeated.
(setq success t))
- (404
+ (not-found ; 404
;; Not found
(setq success t))
- (405
+ (method-not-allowed ; 405
;; The method specified in the Request-Line is not allowed
;; for the resource identified by the Request-URI. The
;; response MUST include an Allow header containing a list of
;; valid methods for the requested resource.
(setq success t))
- (406
+ (not-acceptable ; 406
;; The resource identified by the request is only capable of
;; generating response entities which have content
;; characteristics nota cceptable according to the accept
;; headers sent in the request.
(setq success t))
- (407
+ (proxy-authentication-required ; 407
;; This code is similar to 401 (Unauthorized), but indicates
;; that the client must first authenticate itself with the
;; proxy. The proxy MUST return a Proxy-Authenticate header
;; field containing a challenge applicable to the proxy for
;; the requested resource.
(url-http-handle-authentication t))
- (408
+ (request-timeout ; 408
;; The client did not produce a request within the time that
;; the server was prepared to wait. The client MAY repeat
;; the request without modifications at any later time.
(setq success t))
- (409
+ (conflict ; 409
;; The request could not be completed due to a conflict with
;; the current state of the resource. This code is only
;; allowed in situations where it is expected that the user
@@ -673,11 +724,11 @@
;; information for the user to recognize the source of the
;; conflict.
(setq success t))
- (410
+ (gone ; 410
;; The requested resource is no longer available at the
;; server and no forwarding address is known.
(setq success t))
- (411
+ (length-required ; 411
;; The server refuses to accept the request without a defined
;; Content-Length. The client MAY repeat the request if it
;; adds a valid Content-Length header field containing the
@@ -687,29 +738,29 @@
;; `url-http-create-request' automatically calculates the
;; content-length.
(setq success t))
- (412
+ (precondition-failed ; 412
;; The precondition given in one or more of the
;; request-header fields evaluated to false when it was
;; tested on the server.
(setq success t))
- ((413 414)
+ ((request-entity-too-large request-uri-too-large) ; 413 414
;; The server is refusing to process a request because the
;; request entity|URI is larger than the server is willing or
;; able to process.
(setq success t))
- (415
+ (unsupported-media-type ; 415
;; The server is refusing to service the request because the
;; entity of the request is in a format not supported by the
;; requested resource for the requested method.
(setq success t))
- (416
+ (requested-range-not-satisfiable ; 416
;; A server SHOULD return a response with this status code if
;; a request included a Range request-header field, and none
;; of the range-specifier values in this field overlap the
;; current extent of the selected resource, and the request
;; did not include an If-Range request-header field.
(setq success t))
- (417
+ (expectation-failed ; 417
;; The expectation given in an Expect request-header field
;; could not be met by this server, or, if the server is a
;; proxy, the server has unambiguous evidence that the
@@ -736,16 +787,16 @@
;; 507 Insufficient storage
(setq success t)
(case url-http-response-status
- (501
+ (not-implemented ; 501
;; The server does not support the functionality required to
;; fulfill the request.
nil)
- (502
+ (bad-gateway ; 502
;; The server, while acting as a gateway or proxy, received
;; an invalid response from the upstream server it accessed
;; in attempting to fulfill the request.
nil)
- (503
+ (service-unavailable ; 503
;; The server is currently unable to handle the request due
;; to a temporary overloading or maintenance of the server.
;; The implication is that this is a temporary condition
@@ -754,19 +805,19 @@
;; header. If no Retry-After is given, the client SHOULD
;; handle the response as it would for a 500 response.
nil)
- (504
+ (gateway-timeout ; 504
;; The server, while acting as a gateway or proxy, did not
;; receive a timely response from the upstream server
;; specified by the URI (e.g. HTTP, FTP, LDAP) or some other
;; auxiliary server (e.g. DNS) it needed to access in
;; attempting to complete the request.
nil)
- (505
+ (http-version-not-supported ; 505
;; The server does not support, or refuses to support, the
;; HTTP protocol version that was used in the request
;; message.
nil)
- (507 ; DAV
+ (insufficient-storage ; 507 (DAV)
;; The method could not be performed on the resource
;; because the server is unable to store the representation
;; needed to successfully complete the request. This
next prev parent reply other threads:[~2010-03-23 15:02 UTC|newest]
Thread overview: 182+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-18 19:11 Translation of http status code to text Lennart Borgman
2010-03-22 1:19 ` Juri Linkov
2010-03-22 13:17 ` Ted Zlatanov
2010-03-22 14:01 ` Stefan Monnier
2010-03-22 14:25 ` Ted Zlatanov
2010-03-22 17:06 ` Ted Zlatanov
2010-03-22 17:55 ` Sven Joachim
2010-03-22 19:23 ` Ted Zlatanov
2010-03-22 20:32 ` Sven Joachim
2010-03-22 21:31 ` Ted Zlatanov
2010-03-23 9:55 ` Juri Linkov
2010-03-23 13:08 ` Lennart Borgman
2010-03-23 14:26 ` face for non-ASCII characters (was: Translation of http status code to text) Ted Zlatanov
2010-03-23 16:28 ` Lennart Borgman
2010-03-23 18:18 ` face for non-ASCII characters Ted Zlatanov
2011-04-15 22:41 ` Ted Zlatanov
2011-04-15 23:07 ` Lennart Borgman
2011-04-16 0:51 ` Ted Zlatanov
2011-04-16 9:10 ` Lennart Borgman
2011-04-16 15:05 ` Ted Zlatanov
2011-04-16 15:28 ` Lennart Borgman
2011-04-16 15:42 ` Ted Zlatanov
2011-04-16 15:50 ` Lennart Borgman
2011-04-16 15:57 ` Ted Zlatanov
2011-04-16 16:01 ` Lennart Borgman
2011-04-16 16:13 ` Ted Zlatanov
2011-04-16 16:22 ` Lennart Borgman
2011-04-16 16:27 ` Drew Adams
2011-04-16 16:45 ` Ted Zlatanov
2011-04-16 16:48 ` Lennart Borgman
2011-04-16 16:55 ` Ted Zlatanov
2011-04-16 17:11 ` Lennart Borgman
2011-04-18 15:48 ` Ted Zlatanov
2011-04-18 15:53 ` Lennart Borgman
2011-04-18 16:20 ` Ted Zlatanov
2011-04-18 17:03 ` Lennart Borgman
2011-04-19 13:07 ` Ted Zlatanov
2011-04-19 18:56 ` Lennart Borgman
2011-04-20 14:49 ` Ted Zlatanov
2011-04-20 21:38 ` Lennart Borgman
2011-04-21 17:35 ` Ted Zlatanov
2011-04-21 18:42 ` Lennart Borgman
2011-04-21 19:14 ` Ted Zlatanov
2011-04-21 20:00 ` Lennart Borgman
2011-04-21 20:35 ` Ted Zlatanov
2011-04-21 20:53 ` Lennart Borgman
2011-04-21 21:18 ` Ted Zlatanov
2011-04-22 12:20 ` Lennart Borgman
2011-04-22 12:49 ` Stephen J. Turnbull
2011-04-22 13:23 ` Lennart Borgman
2011-04-23 0:50 ` Richard Stallman
2011-04-23 7:13 ` Lennart Borgman
2011-04-25 17:54 ` Richard Stallman
2011-04-26 18:26 ` Chong Yidong
2011-04-26 19:05 ` Ted Zlatanov
2011-04-26 20:29 ` Chong Yidong
2011-04-27 3:45 ` Ted Zlatanov
2011-04-27 4:42 ` Stephen J. Turnbull
2011-05-02 18:18 ` Ted Zlatanov
2011-05-03 1:50 ` Stephen J. Turnbull
2011-05-03 14:45 ` Ted Zlatanov
2011-05-03 21:21 ` Lennart Borgman
2011-05-04 14:41 ` Stephen J. Turnbull
2011-04-27 12:41 ` Lennart Borgman
2011-04-22 14:20 ` Ted Zlatanov
2011-04-22 17:12 ` Lennart Borgman
2011-04-26 3:14 ` package management proposals for Emacs (was: face for non-ASCII characters) Ted Zlatanov
2011-04-26 8:10 ` Lennart Borgman
2011-04-26 21:46 ` Richard Stallman
2011-04-27 1:19 ` package management proposals for Emacs Stefan Monnier
2011-04-27 3:36 ` Ted Zlatanov
2011-04-27 21:14 ` Richard Stallman
2011-04-26 3:09 ` markchars.el 0.2.0 and idn.el (was: face for non-ASCII characters) Ted Zlatanov
2011-04-26 8:13 ` Lennart Borgman
2011-04-26 15:28 ` idn.el and confusables.txt (was: markchars.el 0.2.0 and idn.el) Ted Zlatanov
2011-05-13 19:42 ` idn.el and confusables.txt Stefan Monnier
2011-05-13 20:19 ` Ted Zlatanov
2011-05-14 8:13 ` Eli Zaretskii
2011-05-14 8:06 ` Eli Zaretskii
2011-05-14 8:56 ` Lennart Borgman
2011-05-14 9:36 ` Eli Zaretskii
2011-05-14 13:40 ` Ted Zlatanov
2011-05-14 14:38 ` Eli Zaretskii
2011-05-14 15:30 ` Ted Zlatanov
2011-05-14 16:42 ` Eli Zaretskii
2011-05-14 17:06 ` Ted Zlatanov
2011-05-14 20:59 ` Eli Zaretskii
2011-05-15 1:22 ` Ted Zlatanov
2011-05-15 5:56 ` Eli Zaretskii
2011-05-15 12:14 ` Ted Zlatanov
2011-05-16 12:38 ` Eli Zaretskii
2011-05-16 18:31 ` Ted Zlatanov
2011-05-17 17:59 ` Eli Zaretskii
2011-05-17 15:32 ` Ted Zlatanov
2011-05-18 18:15 ` Ted Zlatanov
2011-05-14 17:25 ` Stefan Monnier
2011-05-15 13:06 ` Kenichi Handa
2011-05-15 17:34 ` Eli Zaretskii
2011-05-18 5:23 ` handa
2011-05-18 7:38 ` Eli Zaretskii
2011-05-18 7:59 ` handa
2011-05-18 8:13 ` Eli Zaretskii
2011-06-17 8:15 ` Kenichi Handa
2011-06-17 15:12 ` Eli Zaretskii
2011-06-21 2:07 ` Kenichi Handa
2011-06-21 2:53 ` Eli Zaretskii
2011-06-21 3:29 ` Kenichi Handa
2011-06-21 6:11 ` Eli Zaretskii
2011-06-21 7:22 ` Kenichi Handa
2011-06-21 7:34 ` Eli Zaretskii
2011-06-21 8:02 ` Kenichi Handa
2011-06-21 10:30 ` bidi at startup (was: idn.el and confusables.txt) Eli Zaretskii
2011-06-21 15:12 ` bidi at startup Stefan Monnier
2011-06-21 17:13 ` Eli Zaretskii
2011-06-22 15:32 ` Stefan Monnier
2011-07-07 6:10 ` C interface to Unicode character property char-tables Kenichi Handa
2011-08-06 16:52 ` Using uniprop_table_lookup (was: idn.el and confusables.txt) Eli Zaretskii
2011-08-09 0:55 ` Kenichi Handa
2011-08-09 1:32 ` Using uniprop_table_lookup Stefan Monnier
2011-08-09 4:31 ` Kenichi Handa
2011-08-15 8:57 ` Eli Zaretskii
2011-05-31 10:42 ` uni-confusables 0.1 is on the Emacs ELPA branch (was: idn.el and confusables.txt) Ted Zlatanov
2011-06-08 10:42 ` uni-confusables 0.1 is on the Emacs ELPA branch Ted Zlatanov
2011-06-08 15:22 ` Stefan Monnier
2011-04-16 16:00 ` face for non-ASCII characters Drew Adams
2010-03-23 19:40 ` Florian Beck
2010-03-23 14:35 ` Translation of http status code to text Miles Bader
2010-03-23 14:22 ` highlighting non-ASCII characters (was: Translation of http status code to text) Ted Zlatanov
2010-03-23 16:50 ` highlighting non-ASCII characters (was: Translation of http statuscode " Drew Adams
2010-03-23 21:49 ` highlighting non-ASCII characters Stefan Monnier
2010-03-23 21:53 ` Drew Adams
2010-03-24 0:45 ` Stefan Monnier
2010-03-24 1:03 ` Ted Zlatanov
2010-03-24 2:47 ` Stefan Monnier
2010-03-24 4:20 ` Eli Zaretskii
2010-03-24 5:14 ` Jason Rumney
2010-03-24 13:25 ` Stefan Monnier
2010-03-24 15:06 ` Jason Rumney
2010-03-24 19:47 ` Ted Zlatanov
2010-03-24 10:05 ` Ted Zlatanov
2010-03-24 16:21 ` Lennart Borgman
2010-03-24 19:34 ` Lennart Borgman
2010-03-26 17:35 ` Ted Zlatanov
2010-03-26 20:43 ` Ted Zlatanov
2010-03-26 22:50 ` Lennart Borgman
2010-03-29 18:38 ` Ted Zlatanov
2010-03-29 18:48 ` Drew Adams
2010-03-29 20:20 ` Stefan Monnier
2010-03-29 20:19 ` Stefan Monnier
2010-03-29 20:51 ` Lennart Borgman
2010-03-30 13:22 ` Ted Zlatanov
2010-03-29 21:05 ` Ted Zlatanov
2010-03-29 21:31 ` Lennart Borgman
2010-03-29 21:32 ` Drew Adams
2010-03-30 13:15 ` Ted Zlatanov
2010-03-30 14:04 ` Drew Adams
2010-03-30 14:17 ` Lennart Borgman
2010-03-30 14:42 ` Ted Zlatanov
2010-03-30 16:18 ` Juri Linkov
2010-03-30 1:45 ` Stefan Monnier
2010-03-25 7:11 ` Juri Linkov
2010-03-25 14:07 ` Lennart Borgman
2010-03-25 17:32 ` Juri Linkov
2010-03-26 0:32 ` Lennart Borgman
2010-03-26 13:38 ` Stephen Berman
2010-03-26 22:44 ` Lennart Borgman
2010-03-25 7:12 ` Juri Linkov
2010-03-24 2:09 ` Drew Adams
2010-03-24 5:00 ` Stephen J. Turnbull
2010-03-24 9:28 ` Juri Linkov
2010-03-24 13:15 ` Ted Zlatanov
2010-03-24 9:27 ` Juri Linkov
2010-03-22 18:41 ` Translation of http status code to text Stefan Monnier
2010-03-22 19:15 ` Ted Zlatanov
2010-03-23 9:54 ` Juri Linkov
2010-03-23 10:54 ` joakim
2010-03-23 15:02 ` Ted Zlatanov [this message]
2010-03-24 3:22 ` Stefan Monnier
2010-03-24 17:35 ` Glenn Morris
2010-03-24 19:37 ` Ted Zlatanov
2010-03-25 1:16 ` Ted Zlatanov
2010-03-23 12:57 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ocifxerj.fsf@lifelogs.com \
--to=tzz@lifelogs.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.