aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Zlatanov2010-03-24 04:30:28 -0500
committerTed Zlatanov2010-03-24 04:30:28 -0500
commit1e9d758c2f4584e34eeeb2524ce3161842032cbe (patch)
tree4e39f4cb9d54b065267f407daa49fa8f8e2f357c
parent7e26396796ba951b629d44766390b1f1843bab7d (diff)
downloademacs-1e9d758c2f4584e34eeeb2524ce3161842032cbe.tar.gz
emacs-1e9d758c2f4584e34eeeb2524ce3161842032cbe.zip
Add a list of HTTP status code symbols and their text, mapped by number.
* url-http.el (url-http-codes): New variable to hold a mapping of HTTP status codes' numbers, their symbolic name, and their text. (url-http-parse-headers): Use it, leaving the original numeric code in a comment.
-rw-r--r--lisp/url/ChangeLog7
-rw-r--r--lisp/url/url-http.el115
2 files changed, 90 insertions, 32 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog
index 639c919924e..fc4bca157af 100644
--- a/lisp/url/ChangeLog
+++ b/lisp/url/ChangeLog
@@ -1,3 +1,10 @@
12010-03-24 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * url-http.el (url-http-codes): New variable to hold a mapping of
4 HTTP status codes' numbers, their symbolic name, and their text.
5 (url-http-parse-headers): Use it, leaving the original numeric
6 code in a comment.
7
12010-03-19 Glenn Morris <rgm@gnu.org> 82010-03-19 Glenn Morris <rgm@gnu.org>
2 9
3 * url.el: Move mailcap require earlier in the file. 10 * url.el: Move mailcap require earlier in the file.
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 8c203c0eb87..4d734815c97 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -64,6 +64,55 @@ This is only useful when debugging the HTTP subsystem. Setting to
64nil will explicitly close the connection to the server after every 64nil will explicitly close the connection to the server after every
65request.") 65request.")
66 66
67(defconst url-http-codes
68 '((100 continue "Continue with request")
69 (101 switching-protocols "Switching protocols")
70 (102 processing "Processing (Added by DAV)")
71 (200 OK "OK")
72 (201 created "Created")
73 (202 accepted "Accepted")
74 (203 non-authoritative "Non-authoritative information")
75 (204 no-content "No content")
76 (205 reset-content "Reset content")
77 (206 partial-content "Partial content")
78 (207 multi-status "Multi-status (Added by DAV)")
79 (300 multiple-choices "Multiple choices")
80 (301 moved-permanently "Moved permanently")
81 (302 found "Found")
82 (303 see-other "See other")
83 (304 not-modified "Not modified")
84 (305 use-proxy "Use proxy")
85 (307 temporary-redirect "Temporary redirect")
86 (400 bad-request "Bad Request")
87 (401 unauthorized "Unauthorized")
88 (402 payment-required "Payment required")
89 (403 forbidden "Forbidden")
90 (404 not-found "Not found")
91 (405 method-not-allowed "Method not allowed")
92 (406 not-acceptable "Not acceptable")
93 (407 proxy-authentication-required "Proxy authentication required")
94 (408 request-timeout "Request time-out")
95 (409 conflict "Conflict")
96 (410 gone "Gone")
97 (411 length-required "Length required")
98 (412 precondition-failed "Precondition failed")
99 (413 request-entity-too-large "Request entity too large")
100 (414 request-uri-too-large "Request-URI too large")
101 (415 unsupported-media-type "Unsupported media type")
102 (416 requested-range-not-satisfiable "Requested range not satisfiable")
103 (417 expectation-failed "Expectation failed")
104 (422 unprocessable-entity "Unprocessable Entity (Added by DAV)")
105 (423 locked "Locked")
106 (424 failed-Dependency "Failed Dependency")
107 (500 internal-server-error "Internal server error")
108 (501 not-implemented "Not implemented")
109 (502 bad-gateway "Bad gateway")
110 (503 service-unavailable "Service unavailable")
111 (504 gateway-timeout "Gateway time-out")
112 (505 http-version-not-supported "HTTP version not supported")
113 (507 insufficient-storage "Insufficient storage")
114"The HTTP return codes and their text."))
115
67;(eval-when-compile 116;(eval-when-compile
68;; These are all macros so that they are hidden from external sight 117;; These are all macros so that they are hidden from external sight
69;; when the file is byte-compiled. 118;; when the file is byte-compiled.
@@ -435,7 +484,9 @@ should be shown to the user."
435 (delete-process url-http-process))))) 484 (delete-process url-http-process)))))
436 (let ((buffer (current-buffer)) 485 (let ((buffer (current-buffer))
437 (class nil) 486 (class nil)
438 (success nil)) 487 (success nil)
488 ;; other status symbols: jewelry and luxury cars
489 (status-symbol (cadr (assq status-number url-http-codes))))
439 (setq class (/ url-http-response-status 100)) 490 (setq class (/ url-http-response-status 100))
440 (url-http-debug "Parsed HTTP headers: class=%d status=%d" class url-http-response-status) 491 (url-http-debug "Parsed HTTP headers: class=%d status=%d" class url-http-response-status)
441 (url-http-handle-cookies) 492 (url-http-handle-cookies)
@@ -463,8 +514,8 @@ should be shown to the user."
463 ;; 205 Reset content 514 ;; 205 Reset content
464 ;; 206 Partial content 515 ;; 206 Partial content
465 ;; 207 Multi-status (Added by DAV) 516 ;; 207 Multi-status (Added by DAV)
466 (case url-http-response-status 517 (case status-symbol
467 ((204 205) 518 ((no-content reset-content)
468 ;; No new data, just stay at the same document 519 ;; No new data, just stay at the same document
469 (url-mark-buffer-as-dead buffer) 520 (url-mark-buffer-as-dead buffer)
470 (setq success t)) 521 (setq success t))
@@ -485,8 +536,8 @@ should be shown to the user."
485 ;; 307 Temporary redirect 536 ;; 307 Temporary redirect
486 (let ((redirect-uri (or (mail-fetch-field "Location") 537 (let ((redirect-uri (or (mail-fetch-field "Location")
487 (mail-fetch-field "URI")))) 538 (mail-fetch-field "URI"))))
488 (case url-http-response-status 539 (case status-symbol
489 (300 540 (multiple-choices ; 300
490 ;; Quoth the spec (section 10.3.1) 541 ;; Quoth the spec (section 10.3.1)
491 ;; ------------------------------- 542 ;; -------------------------------
492 ;; The requested resource corresponds to any one of a set of 543 ;; The requested resource corresponds to any one of a set of
@@ -503,7 +554,7 @@ should be shown to the user."
503 ;; We do not support agent-driven negotiation, so we just 554 ;; We do not support agent-driven negotiation, so we just
504 ;; redirect to the preferred URI if one is provided. 555 ;; redirect to the preferred URI if one is provided.
505 nil) 556 nil)
506 ((301 302 307) 557 ((moved-permanently found temporary-redirect) ; 301 302 307
507 ;; If the 301|302 status code is received in response to a 558 ;; If the 301|302 status code is received in response to a
508 ;; request other than GET or HEAD, the user agent MUST NOT 559 ;; request other than GET or HEAD, the user agent MUST NOT
509 ;; automatically redirect the request unless it can be 560 ;; automatically redirect the request unless it can be
@@ -519,20 +570,20 @@ should be shown to the user."
519 url-http-method url-http-response-status) 570 url-http-method url-http-response-status)
520 (setq url-http-method "GET" 571 (setq url-http-method "GET"
521 url-http-data nil))) 572 url-http-data nil)))
522 (303 573 (see-other ; 303
523 ;; The response to the request can be found under a different 574 ;; The response to the request can be found under a different
524 ;; URI and SHOULD be retrieved using a GET method on that 575 ;; URI and SHOULD be retrieved using a GET method on that
525 ;; resource. 576 ;; resource.
526 (setq url-http-method "GET" 577 (setq url-http-method "GET"
527 url-http-data nil)) 578 url-http-data nil))
528 (304 579 (not-modified ; 304
529 ;; The 304 response MUST NOT contain a message-body. 580 ;; The 304 response MUST NOT contain a message-body.
530 (url-http-debug "Extracting document from cache... (%s)" 581 (url-http-debug "Extracting document from cache... (%s)"
531 (url-cache-create-filename (url-view-url t))) 582 (url-cache-create-filename (url-view-url t)))
532 (url-cache-extract (url-cache-create-filename (url-view-url t))) 583 (url-cache-extract (url-cache-create-filename (url-view-url t)))
533 (setq redirect-uri nil 584 (setq redirect-uri nil
534 success t)) 585 success t))
535 (305 586 (use-proxy ; 305
536 ;; The requested resource MUST be accessed through the 587 ;; The requested resource MUST be accessed through the
537 ;; proxy given by the Location field. The Location field 588 ;; proxy given by the Location field. The Location field
538 ;; gives the URI of the proxy. The recipient is expected 589 ;; gives the URI of the proxy. The recipient is expected
@@ -620,51 +671,51 @@ should be shown to the user."
620 ;; 422 Unprocessable Entity (Added by DAV) 671 ;; 422 Unprocessable Entity (Added by DAV)
621 ;; 423 Locked 672 ;; 423 Locked
622 ;; 424 Failed Dependency 673 ;; 424 Failed Dependency
623 (case url-http-response-status 674 (case status-symbol
624 (401 675 (unauthorized ; 401
625 ;; The request requires user authentication. The response 676 ;; The request requires user authentication. The response
626 ;; MUST include a WWW-Authenticate header field containing a 677 ;; MUST include a WWW-Authenticate header field containing a
627 ;; challenge applicable to the requested resource. The 678 ;; challenge applicable to the requested resource. The
628 ;; client MAY repeat the request with a suitable 679 ;; client MAY repeat the request with a suitable
629 ;; Authorization header field. 680 ;; Authorization header field.
630 (url-http-handle-authentication nil)) 681 (url-http-handle-authentication nil))
631 (402 682 (payment-required ; 402
632 ;; This code is reserved for future use 683 ;; This code is reserved for future use
633 (url-mark-buffer-as-dead buffer) 684 (url-mark-buffer-as-dead buffer)
634 (error "Somebody wants you to give them money")) 685 (error "Somebody wants you to give them money"))
635 (403 686 (forbidden ; 403
636 ;; The server understood the request, but is refusing to 687 ;; The server understood the request, but is refusing to
637 ;; fulfill it. Authorization will not help and the request 688 ;; fulfill it. Authorization will not help and the request
638 ;; SHOULD NOT be repeated. 689 ;; SHOULD NOT be repeated.
639 (setq success t)) 690 (setq success t))
640 (404 691 (not-found ; 404
641 ;; Not found 692 ;; Not found
642 (setq success t)) 693 (setq success t))
643 (405 694 (method-not-allowed ; 405
644 ;; The method specified in the Request-Line is not allowed 695 ;; The method specified in the Request-Line is not allowed
645 ;; for the resource identified by the Request-URI. The 696 ;; for the resource identified by the Request-URI. The
646 ;; response MUST include an Allow header containing a list of 697 ;; response MUST include an Allow header containing a list of
647 ;; valid methods for the requested resource. 698 ;; valid methods for the requested resource.
648 (setq success t)) 699 (setq success t))
649 (406 700 (not-acceptable ; 406
650 ;; The resource identified by the request is only capable of 701 ;; The resource identified by the request is only capable of
651 ;; generating response entities which have content 702 ;; generating response entities which have content
652 ;; characteristics nota cceptable according to the accept 703 ;; characteristics nota cceptable according to the accept
653 ;; headers sent in the request. 704 ;; headers sent in the request.
654 (setq success t)) 705 (setq success t))
655 (407 706 (proxy-authentication-required ; 407
656 ;; This code is similar to 401 (Unauthorized), but indicates 707 ;; This code is similar to 401 (Unauthorized), but indicates
657 ;; that the client must first authenticate itself with the 708 ;; that the client must first authenticate itself with the
658 ;; proxy. The proxy MUST return a Proxy-Authenticate header 709 ;; proxy. The proxy MUST return a Proxy-Authenticate header
659 ;; field containing a challenge applicable to the proxy for 710 ;; field containing a challenge applicable to the proxy for
660 ;; the requested resource. 711 ;; the requested resource.
661 (url-http-handle-authentication t)) 712 (url-http-handle-authentication t))
662 (408 713 (request-timeout ; 408
663 ;; The client did not produce a request within the time that 714 ;; The client did not produce a request within the time that
664 ;; the server was prepared to wait. The client MAY repeat 715 ;; the server was prepared to wait. The client MAY repeat
665 ;; the request without modifications at any later time. 716 ;; the request without modifications at any later time.
666 (setq success t)) 717 (setq success t))
667 (409 718 (conflict ; 409
668 ;; The request could not be completed due to a conflict with 719 ;; The request could not be completed due to a conflict with
669 ;; the current state of the resource. This code is only 720 ;; the current state of the resource. This code is only
670 ;; allowed in situations where it is expected that the user 721 ;; allowed in situations where it is expected that the user
@@ -673,11 +724,11 @@ should be shown to the user."
673 ;; information for the user to recognize the source of the 724 ;; information for the user to recognize the source of the
674 ;; conflict. 725 ;; conflict.
675 (setq success t)) 726 (setq success t))
676 (410 727 (gone ; 410
677 ;; The requested resource is no longer available at the 728 ;; The requested resource is no longer available at the
678 ;; server and no forwarding address is known. 729 ;; server and no forwarding address is known.
679 (setq success t)) 730 (setq success t))
680 (411 731 (length-required ; 411
681 ;; The server refuses to accept the request without a defined 732 ;; The server refuses to accept the request without a defined
682 ;; Content-Length. The client MAY repeat the request if it 733 ;; Content-Length. The client MAY repeat the request if it
683 ;; adds a valid Content-Length header field containing the 734 ;; adds a valid Content-Length header field containing the
@@ -687,29 +738,29 @@ should be shown to the user."
687 ;; `url-http-create-request' automatically calculates the 738 ;; `url-http-create-request' automatically calculates the
688 ;; content-length. 739 ;; content-length.
689 (setq success t)) 740 (setq success t))
690 (412 741 (precondition-failed ; 412
691 ;; The precondition given in one or more of the 742 ;; The precondition given in one or more of the
692 ;; request-header fields evaluated to false when it was 743 ;; request-header fields evaluated to false when it was
693 ;; tested on the server. 744 ;; tested on the server.
694 (setq success t)) 745 (setq success t))
695 ((413 414) 746 ((request-entity-too-large request-uri-too-large) ; 413 414
696 ;; The server is refusing to process a request because the 747 ;; The server is refusing to process a request because the
697 ;; request entity|URI is larger than the server is willing or 748 ;; request entity|URI is larger than the server is willing or
698 ;; able to process. 749 ;; able to process.
699 (setq success t)) 750 (setq success t))
700 (415 751 (unsupported-media-type ; 415
701 ;; The server is refusing to service the request because the 752 ;; The server is refusing to service the request because the
702 ;; entity of the request is in a format not supported by the 753 ;; entity of the request is in a format not supported by the
703 ;; requested resource for the requested method. 754 ;; requested resource for the requested method.
704 (setq success t)) 755 (setq success t))
705 (416 756 (requested-range-not-satisfiable ; 416
706 ;; A server SHOULD return a response with this status code if 757 ;; A server SHOULD return a response with this status code if
707 ;; a request included a Range request-header field, and none 758 ;; a request included a Range request-header field, and none
708 ;; of the range-specifier values in this field overlap the 759 ;; of the range-specifier values in this field overlap the
709 ;; current extent of the selected resource, and the request 760 ;; current extent of the selected resource, and the request
710 ;; did not include an If-Range request-header field. 761 ;; did not include an If-Range request-header field.
711 (setq success t)) 762 (setq success t))
712 (417 763 (expectation-failed ; 417
713 ;; The expectation given in an Expect request-header field 764 ;; The expectation given in an Expect request-header field
714 ;; could not be met by this server, or, if the server is a 765 ;; could not be met by this server, or, if the server is a
715 ;; proxy, the server has unambiguous evidence that the 766 ;; proxy, the server has unambiguous evidence that the
@@ -736,16 +787,16 @@ should be shown to the user."
736 ;; 507 Insufficient storage 787 ;; 507 Insufficient storage
737 (setq success t) 788 (setq success t)
738 (case url-http-response-status 789 (case url-http-response-status
739 (501 790 (not-implemented ; 501
740 ;; The server does not support the functionality required to 791 ;; The server does not support the functionality required to
741 ;; fulfill the request. 792 ;; fulfill the request.
742 nil) 793 nil)
743 (502 794 (bad-gateway ; 502
744 ;; The server, while acting as a gateway or proxy, received 795 ;; The server, while acting as a gateway or proxy, received
745 ;; an invalid response from the upstream server it accessed 796 ;; an invalid response from the upstream server it accessed
746 ;; in attempting to fulfill the request. 797 ;; in attempting to fulfill the request.
747 nil) 798 nil)
748 (503 799 (service-unavailable ; 503
749 ;; The server is currently unable to handle the request due 800 ;; The server is currently unable to handle the request due
750 ;; to a temporary overloading or maintenance of the server. 801 ;; to a temporary overloading or maintenance of the server.
751 ;; The implication is that this is a temporary condition 802 ;; The implication is that this is a temporary condition
@@ -754,19 +805,19 @@ should be shown to the user."
754 ;; header. If no Retry-After is given, the client SHOULD 805 ;; header. If no Retry-After is given, the client SHOULD
755 ;; handle the response as it would for a 500 response. 806 ;; handle the response as it would for a 500 response.
756 nil) 807 nil)
757 (504 808 (gateway-timeout ; 504
758 ;; The server, while acting as a gateway or proxy, did not 809 ;; The server, while acting as a gateway or proxy, did not
759 ;; receive a timely response from the upstream server 810 ;; receive a timely response from the upstream server
760 ;; specified by the URI (e.g. HTTP, FTP, LDAP) or some other 811 ;; specified by the URI (e.g. HTTP, FTP, LDAP) or some other
761 ;; auxiliary server (e.g. DNS) it needed to access in 812 ;; auxiliary server (e.g. DNS) it needed to access in
762 ;; attempting to complete the request. 813 ;; attempting to complete the request.
763 nil) 814 nil)
764 (505 815 (http-version-not-supported ; 505
765 ;; The server does not support, or refuses to support, the 816 ;; The server does not support, or refuses to support, the
766 ;; HTTP protocol version that was used in the request 817 ;; HTTP protocol version that was used in the request
767 ;; message. 818 ;; message.
768 nil) 819 nil)
769 (507 ; DAV 820 (insufficient-storage ; 507 (DAV)
770 ;; The method could not be performed on the resource 821 ;; The method could not be performed on the resource
771 ;; because the server is unable to store the representation 822 ;; because the server is unable to store the representation
772 ;; needed to successfully complete the request. This 823 ;; needed to successfully complete the request. This