From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ryan Raymond Newsgroups: gmane.lisp.guile.devel Subject: Custom HTTP methods in web module Date: Wed, 20 Mar 2024 18:14:42 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000eb9dd506141eeb0b" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16345"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed Mar 20 23:15:33 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rn4Dd-00043K-2d for guile-devel@m.gmane-mx.org; Wed, 20 Mar 2024 23:15:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rn4DM-0005Rg-JO; Wed, 20 Mar 2024 18:15:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rn4DL-0005Kx-4Q for guile-devel@gnu.org; Wed, 20 Mar 2024 18:15:15 -0400 Original-Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rn4DA-0002vR-Tb for guile-devel@gnu.org; Wed, 20 Mar 2024 18:15:14 -0400 Original-Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5d4a1e66750so198168a12.0 for ; Wed, 20 Mar 2024 15:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oakland.edu; s=google; t=1710972900; x=1711577700; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=WrNiFQ3zLZuvyhYt7PC5LkpcaWbfldBDfLB1+obJQwM=; b=AfTq0sGsnxyIbWScgZWe3FwXgWcVGOeEuccA/qPRBPUi3JcZedliQ4k6pwf1n6G/yP CwuxfsPa3IVEFPgcyO16RI5LHlBdbket10O+MBvNpIjI4ABX5DWre84/39OxxeOx5S/z UdJ/G85CSU/eg6ScJZdX6ebe09a4iiRipwJJQSk7/+ht4yB/eHuhu0t5SSiRl7KAsWqy kLMAuSZhtD6i79sBvKtegFMamN3nxRwD/REO9en5jLdcb7xc+A45TqG/orWPawthoB9m PGSQPJAbHHSCEdyAbrSEclGDqyC7VAJE7Wrbs5sLmvsRw9nBy3qe3An10cd5XaEYTP8T u28Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710972900; x=1711577700; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WrNiFQ3zLZuvyhYt7PC5LkpcaWbfldBDfLB1+obJQwM=; b=kDbsCTXuHf/LMgWhWckQxecfFOKeHbRCOUp5cKdRzq/3uidKZ4l/emkKfekKurF/aQ gPx9wz/HDlruZ6BiPhXwNj5/QPsECmyxusyrzUm1LAilBNDGlr7MdnZwAMkVgU/pjMAh w5XXsI/ll9u1q7vLhw5RZhSgIjAgwknuemCgGssKYqqnoxZUt9edz9tCB9KYjbfxoyKn os0WtIh+BnuwKKfbn/M21hNX+FkxTRqG/zs3pWMFLCuE7ggG18CsdYRqRWqaxCz7cGsi OH1MSJ16VOXc3xvt/1yhYPEQ0Nbi0W/O3DsbhJSib3dtc8Bi6ZMseqTB5hs9qDF3lM6L lBEw== X-Gm-Message-State: AOJu0YzKbrKLeGr+rZKlVdOMXywFhPEER/U/UQXBUzxwhzsLwpZzrcxA XRLgnkktWeTbh80PoD6eHWQjhbIG3WvbcHgjGewgi4viHK0QR+9OzVTcYP92CBdjkXYTKjSEeno d930FmZd8SEDfbGcYjaljOhrINqoYow8c7hpkQHurH8TSc008IA== X-Google-Smtp-Source: AGHT+IFXAXeT4Bj4wPbulhuHF9EAOmEZxPE+yoAny/kPQVhuyahy5ca6yBukUmYuKOMUueDLc2ilaZ9dulqCpv3OJko= X-Received: by 2002:a17:90a:e60d:b0:29f:8b48:b390 with SMTP id j13-20020a17090ae60d00b0029f8b48b390mr3021357pjy.16.1710972899898; Wed, 20 Mar 2024 15:14:59 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=rjraymond@oakland.edu; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22359 Archived-At: --000000000000eb9dd506141eeb0b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 =E2=80=98GET=E2=80=99." (cond ((string=3D str "GET" start end) 'GET) ((string=3D str "HEAD" start end) 'HEAD) ((string=3D str "POST" start end) 'POST) ((string=3D str "PUT" start end) 'PUT) ((string=3D str "DELETE" start end) 'DELETE) ((string=3D str "OPTIONS" start end) 'OPTIONS) ((string=3D str "TRACE" start end) 'TRACE) ((string=3D str "CONNECT" start end) 'CONNECT) ((string=3D 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 =E2=80=98GET=E2=80=99." (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 --000000000000eb9dd506141eeb0b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, all.
Please consider the following c= ode snippet from /module/web/http.scm:

(define= * (parse-http-method str #:optional (start 0) (end (string-length str)))=C2=A0 "Parse an HTTP method from STR.=C2=A0 The result is an upper-c= ase
symbol, like =E2=80=98GET=E2=80=99."
=C2=A0 (cond
=C2=A0 = =C2=A0((string=3D str "GET" start end) 'GET)
=C2=A0 =C2=A0= ((string=3D str "HEAD" start end) 'HEAD)
=C2=A0 =C2=A0((st= ring=3D str "POST" start end) 'POST)
=C2=A0 =C2=A0((string= =3D str "PUT" start end) 'PUT)
=C2=A0 =C2=A0((string=3D st= r "DELETE" start end) 'DELETE)
=C2=A0 =C2=A0((string=3D st= r "OPTIONS" start end) 'OPTIONS)
=C2=A0 =C2=A0((string=3D = str "TRACE" start end) 'TRACE)
=C2=A0 =C2=A0((string=3D st= r "CONNECT" start end) 'CONNECT)
=C2=A0 =C2=A0((string=3D = str "PATCH" start end) 'PATCH)
=C2=A0 =C2=A0(else (bad-req= uest "Invalid method: ~a" (substring str start end)))))

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

(define* (parse-http-method str #:o= ptional (start 0) (end (string-length str)))
=C2=A0 "Parse an HTTP = method from STR.=C2=A0 The result is an upper-case
symbol, like =E2=80= =98GET=E2=80=99."
=C2=A0 =C2=A0(string->symbol (string-upcase (s= ubstring str start end))))

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

Ryan
--000000000000eb9dd506141eeb0b--