Hi all,

Attached you will find a simple patch that would enable cgi-bin
handlers to also serve the http methods DELETE, PUT and OPTIONS. With
this one can implement more advanced APIs.

Let me know if you have any feedback, suggestions or questions,

Thanks!

  - Alexander

p.s. .. and thanks to all of you for making our awesome and beloved busybox :)

-- 
Alexander Sack
Co-Founder
Mobile: +49 177 650 59 78

Pantacor Ltd.
64 Southwark Bridge Road
London, England, SE1 0AS

Company No. 10474766
From 7038af9abfb510cb75721de09d2224a3371e36a3 Mon Sep 17 00:00:00 2001
From: Alexander Sack <[email protected]>
Date: Tue, 4 May 2021 07:41:50 +0000
Subject: [PATCH] httpd: cgi-bin support for DELETE, PUT, OPTIONS methods

Signed-off-by: Alexander Sack <[email protected]>
---
 networking/httpd.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/networking/httpd.c b/networking/httpd.c
index e6757d943..1066ec2b0 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2186,7 +2186,11 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
 	unsigned total_headers_len;
 #endif
 #if ENABLE_FEATURE_HTTPD_CGI
-	static const char request_HEAD[] ALIGN1 = "HEAD";
+	static const char request_HEAD[]    ALIGN1 = "HEAD";
+	static const char request_POST[]    ALIGN1 = "POST";
+	static const char request_PUT[]     ALIGN1 = "PUT";
+	static const char request_DELETE[]  ALIGN1 = "DELETE";
+	static const char request_OPTIONS[] ALIGN1 = "OPTIONS";
 	const char *prequest;
 	unsigned long length = 0;
 	enum CGI_type cgi_type = CGI_NONE;
@@ -2246,16 +2250,33 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
 	prequest = request_GET;
 	if (strcasecmp(iobuf, prequest) != 0) {
 		prequest = request_HEAD;
-		if (strcasecmp(iobuf, prequest) != 0) {
-			prequest = "POST";
-			if (strcasecmp(iobuf, prequest) != 0)
-				send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
-		}
+		if (strcasecmp(iobuf, prequest) == 0)
+		goto found;
+
+		prequest = request_POST;
+		if (strcasecmp(iobuf, prequest) == 0)
+			goto found;
+
+		prequest = request_DELETE;
+		if (strcasecmp(iobuf, prequest) == 0)
+			goto found;
+
+		prequest = request_PUT;
+		if (strcasecmp(iobuf, prequest) == 0)
+			goto found;
+
+		prequest = request_OPTIONS;
+		if (strcasecmp(iobuf, prequest) == 0)
+			goto found;
+
+		send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
 	}
 #else
 	if (strcasecmp(iobuf, request_GET) != 0)
 		send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
 #endif
+
+found:
 	// rfc2616: method and URI is separated by exactly one space
 	//urlp = skip_whitespace(urlp); - should not be necessary
 	if (urlp[0] != '/')
-- 
2.26.3

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to