unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Custom HTTP methods in web module
@ 2024-03-20 22:14 Ryan Raymond
  2024-03-23 12:49 ` Maxime Devos
  2024-03-23 18:50 ` Maxime Devos
  0 siblings, 2 replies; 4+ messages in thread
From: Ryan Raymond @ 2024-03-20 22:14 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1458 bytes --]

Hello, all.
Please consider the following code snippet from /module/web/http.scm:

(define* (parse-http-method str #:optional (start 0) (end (string-length
str)))
  "Parse an HTTP method from STR.  The result is an upper-case
symbol, like ‘GET’."
  (cond
   ((string= str "GET" start end) 'GET)
   ((string= str "HEAD" start end) 'HEAD)
   ((string= str "POST" start end) 'POST)
   ((string= str "PUT" start end) 'PUT)
   ((string= str "DELETE" start end) 'DELETE)
   ((string= str "OPTIONS" start end) 'OPTIONS)
   ((string= str "TRACE" start end) 'TRACE)
   ((string= str "CONNECT" start end) 'CONNECT)
   ((string= str "PATCH" start end) 'PATCH)
   (else (bad-request "Invalid method: ~a" (substring str start end)))))

I do not understand why it is necessary to throw an error on non-standard
http methods. I am working on an application where I will use (for example)
"WAIT" and "SUBSCRIBE". Why not replace the code with, for example:

(define* (parse-http-method str #:optional (start 0) (end (string-length
str)))
  "Parse an HTTP method from STR.  The result is an upper-case
symbol, like ‘GET’."
   (string->symbol (string-upcase (substring str start end))))

This has many advantages. It is probably faster, allows for lowercase
methods (maybe useful?), it has far fewer LOC,
and most importantly it allows us to have custom methods, which is
extremely useful.
Please weigh in with your opinions.

Ryan

[-- Attachment #2: Type: text/html, Size: 1853 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-24 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 22:14 Custom HTTP methods in web module Ryan Raymond
2024-03-23 12:49 ` Maxime Devos
2024-03-23 18:50 ` Maxime Devos
     [not found]   ` <CAGvJ-HS5Laqd7=v=WCn4-2zUurXVZcKDFA2+MmNPO-cZO6iUJg@mail.gmail.com>
2024-03-24 13:57     ` Maxime Devos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).