Dropping WebServer in favor of httpd.

This commit is contained in:
Brad Nelson
2022-02-03 11:34:45 -08:00
parent a76a1f9149
commit 7fb96c4dd1
7 changed files with 65 additions and 83 deletions

View File

@ -507,7 +507,6 @@ e: test-esp32-forth-namespace
out: SD_MMC
out: SD
out: WiFi
out: WebServer
out: Wire
out: editor
out: streams
@ -571,7 +570,6 @@ e: test-esp32-forth-namespace
out: SD_MMC
out: SD
out: WiFi
out: WebServer
out: Wire
out: ok
check-esp32-basics

View File

@ -25,18 +25,6 @@ transfer{
}transfer
forth definitions
vocabulary WebServer WebServer definitions
transfer{
WebServer.arg WebServer.argi WebServer.argName
WebServer.new WebServer.delete
WebServer.begin WebServer.stop
WebServer.on WebServer.hasArg
WebServer.sendHeader WebServer.send WebServer.sendContent
WebServer.method WebServer.handleClient
WebServer.args WebServer.setContentLength
}transfer
forth definitions
vocabulary WiFi WiFi definitions
transfer{

View File

@ -14,10 +14,6 @@
static char filename[PATH_MAX];
#ifdef ENABLE_WEBSERVER_SUPPORT
static String string_value;
#endif
{{core}}
{{interp}}
{{boot}}
@ -53,24 +49,6 @@ static cell_t ResizeFile(cell_t fd, cell_t size) {
return 0;
}
#ifdef ENABLE_WEBSERVER_SUPPORT
static void InvokeWebServerOn(WebServer *ws, const char *url, cell_t xt) {
ws->on(url, [xt]() {
cell_t code[2];
code[0] = xt;
code[1] = g_sys.YIELD_XT;
cell_t fstack[INTERRUPT_STACK_CELLS];
cell_t rstack[INTERRUPT_STACK_CELLS];
cell_t stack[INTERRUPT_STACK_CELLS];
cell_t *rp = rstack;
*++rp = (cell_t) (fstack + 1);
*++rp = (cell_t) (stack + 1);
*++rp = (cell_t) code;
forth_run(rp);
});
}
#endif
#ifdef ENABLE_INTERRUPTS_SUPPORT
struct handle_interrupt_args {
cell_t xt;

View File

@ -14,10 +14,6 @@
#ifndef SIM_PRINT_ONLY
# ifdef ENABLE_WEBSERVER_SUPPORT
# include "WebServer.h"
# endif
# include <errno.h>
# include <unistd.h>
# include <fcntl.h>
@ -48,7 +44,6 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
OPTIONAL_SPIFFS_SUPPORT \
OPTIONAL_WIFI_SUPPORT \
OPTIONAL_MDNS_SUPPORT \
OPTIONAL_WEBSERVER_SUPPORT \
OPTIONAL_SD_SUPPORT \
OPTIONAL_SD_MMC_SUPPORT \
OPTIONAL_I2C_SUPPORT \
@ -513,43 +508,6 @@ static cell_t FromIP(IPAddress ip) {
X("MDNS.begin", MDNS_BEGIN, n0 = MDNS.begin(c0))
#endif
#ifndef ENABLE_WEBSERVER_SUPPORT
# define OPTIONAL_WEBSERVER_SUPPORT
#else
# ifndef SIM_PRINT_ONLY
# include <WebServer.h>
static void InvokeWebServerOn(WebServer *ws, const char *url, cell_t xt);
# define ws0 ((WebServer *) a0)
# endif
# define OPTIONAL_WEBSERVER_SUPPORT \
/* WebServer */ \
X("WebServer.new", WEBSERVER_NEW, PUSH new WebServer(tos)) \
X("WebServer.delete", WEBSERVER_DELETE, delete ws0; DROP) \
X("WebServer.begin", WEBSERVER_BEGIN, ws0->begin(n1); DROPn(2)) \
X("WebServer.stop", WEBSERVER_STOP, ws0->stop(); DROP) \
X("WebServer.on", WEBSERVER_ON, InvokeWebServerOn(ws0, c2, n1); DROPn(3)) \
X("WebServer.hasArg", WEBSERVER_HAS_ARG, n0 = ws0->hasArg(c1); DROP) \
X("WebServer.arg", WEBSERVER_ARG, \
string_value = ws0->arg(c1); \
c1 = &string_value[0]; n0 = string_value.length()) \
X("WebServer.argi", WEBSERVER_ARGI, \
string_value = ws0->arg(n1); \
c1 = &string_value[0]; n0 = string_value.length()) \
X("WebServer.argName", WEBSERVER_ARG_NAME, \
string_value = ws0->argName(n1); \
c1 = &string_value[0]; n0 = string_value.length()) \
X("WebServer.args", WEBSERVER_ARGS, n0 = ws0->args()) \
X("WebServer.setContentLength", WEBSERVER_SET_CONTENT_LENGTH, \
ws0->setContentLength(n1); DROPn(2)) \
X("WebServer.sendHeader", WEBSERVER_SEND_HEADER, \
ws0->sendHeader(c3, c2, n1); DROPn(4)) \
X("WebServer.send", WEBSERVER_SEND, ws0->send(n3, c2, c1); DROPn(4)) \
X("WebServer.sendContent", WEBSERVER_SEND_CONTENT, \
ws0->sendContent(c1); DROPn(2)) \
X("WebServer.method", WEBSERVER_METHOD, n0 = ws0->method()) \
X("WebServer.handleClient", WEBSERVER_HANDLE_CLIENT, ws0->handleClient(); DROP)
#endif
#ifndef ENABLE_OLED_SUPPORT
# define OPTIONAL_OLED_SUPPORT
#else

View File

@ -0,0 +1,20 @@
#! /usr/bin/env ueforth
also httpd
: handle-index
s" text/html" ok-response r|
<html>
<body>Hi!</body>
</html>
| send ;
: handle1
." Got a request for: " path type cr
path s" /" str= if handle-index exit then
notfound-response
;
: run 8080 server
begin handleClient if handle1 then pause again ;
run

View File

@ -80,14 +80,14 @@ variable goal variable goal#
: path ( -- a n ) 0 bl skipover bl eat rot drop ;
: send ( a n -- ) client-type ;
: response ( mime$ result$ status mime$ -- )
: response ( mime$ result$ status -- )
s" HTTP/1.0 " client-type <# #s #> client-type
bl client-emit client-type client-cr
s" Content-type: " client-type client-type client-cr
client-cr ;
: ok-response ( mime$ -- ) s" OK" 200 response ;
: bad-response ( mime$ -- ) s" text/plain" s" Bad Request" 400 response ;
: notfound-response ( mime$ -- ) s" text/plain" s" Not Found" 404 response ;
: bad-response ( -- ) s" text/plain" s" Bad Request" 400 response ;
: notfound-response ( -- ) s" text/plain" s" Not Found" 404 response ;
only forth definitions
httpd

View File

@ -500,8 +500,9 @@ SPIFFS.totalBytes ( -- n )
SPIFFS.usedBytes ( -- n )
</pre>
<h5>WebServer</h5>
<h5>WebServer (DEPRECATED)</h5>
These words are inside the <code>WebServer</code> vocabulary.
<p><b>Removed in 7.0.6.14</b>, use httpd instead.</p>
<pre>
WebServer.new ( port -- ws ) Allocate new webserver object
WebServer.delete ( ws -- ) Delete webserver object
@ -521,6 +522,45 @@ WebServer.sendContent ( z ws -- )
WebServer.method ( ws -- n ) GET / POST etc.
</pre>
<h5>httpd</h5>
These words are inside the <code>httpd</code> vocabulary.
<pre>
server ( port -- ) Run a webserver on a port (in background, returns immediately).
handleClient ( -- f ) Wait for a client to connect, true if connected.
path ( -- a n ) Get request path.
method ( -- a n ) Get request method (GET/POST).
header ( a n -- a n ) Get header value or empty string.
body ( -- a n ) Get request body.
response ( mime mime# result result# status -- ) Respond with a particular mime type result and status.
ok-response ( mime mime# ) Response with a HTTP 200.
bad-response ( -- ) Response with HTTP 400 Bad request.
notfound-response ( -- ) Response with HTTP 404 Not found.
send ( a n -- ) Send response bytes.
NOTE: You may want to use this feature in tandem with tasks / streams.
Example:
also httpd
: handle-index
s" text/html" ok-response r|
<html>
<body>Hi!</body>
</html>
| send ;
: handle1
." Got a request for: " path type cr
path s" /" str= if handle-index exit then
notfound-response
;
: run 8080 server
begin handleClient if handle1 then pause again ;
run
</pre>
<h5>Wire</h5>
These words are inside the <code>Wire</code> vocabulary.
<pre>