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

Reply via email to