emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Translation of http status code to text


From: Stefan Monnier
Subject: Re: Translation of http status code to text
Date: Tue, 23 Mar 2010 08:57:15 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>>> Here's one version of the HTTP codes as an alist.  I was thinking of
>>> also generating defconst calls based on this list, that's why I named
>>> everything "url-http-code-*".  But maybe that's not necessary and
>>> accessor functions will be enough, so then we can s/url-http-code-//
SM> The symbol part depends on the rest of the patch: what do you use the
SM> symbol for?  Do you even need it?
> I was going to change url-http.el like so, in url-http-parse-headers:

>        (case url-http-response-status
>          ((url-http-code-multiple-choices) ; was 300, uses defconst
> ...
>           nil)
> ...)

I see, then it's OK to add symbols, I guess, but in this case use
shorter ones, so you can do:

  (case (cadr (assq status-number url-http-codes)))
    (OK ...)
    (moved-permanently ...)
    (proxy-authentication-required ...)
    (accepted ...)
    ...)

And in that case, a better option is to create the symbols
programmatically from the error string:

  (defconst url-http-codes
    (mapcar (lambda (x)
              (let ((s (subst-char-in-string ?\s ?- (cadr x))))
                (when (string-match "-(.*)" s)
                  (setq s (substring s 0 (match-beginning 0))))
                (list (car x) (intern (downcase s)) (cadr x))))
     '((100 "Continue with request")
       ...)))


-- Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]