unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ryan Raymond <rjraymond@oakland.edu>
To: guile-devel@gnu.org
Subject: Custom HTTP methods in web module
Date: Wed, 20 Mar 2024 18:14:42 -0400	[thread overview]
Message-ID: <CAGvJ-HSOn7npYqfMOb1shRMf5jJz5xeCxeFH_4iUZi9KmdMvPQ@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2024-03-20 22:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20 22:14 Ryan Raymond [this message]
2024-03-23 12:49 ` Custom HTTP methods in web module 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

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGvJ-HSOn7npYqfMOb1shRMf5jJz5xeCxeFH_4iUZi9KmdMvPQ@mail.gmail.com \
    --to=rjraymond@oakland.edu \
    --cc=guile-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.
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).