Dropping WebServer in favor of httpd.
This commit is contained in:
@ -507,7 +507,6 @@ e: test-esp32-forth-namespace
|
|||||||
out: SD_MMC
|
out: SD_MMC
|
||||||
out: SD
|
out: SD
|
||||||
out: WiFi
|
out: WiFi
|
||||||
out: WebServer
|
|
||||||
out: Wire
|
out: Wire
|
||||||
out: editor
|
out: editor
|
||||||
out: streams
|
out: streams
|
||||||
@ -571,7 +570,6 @@ e: test-esp32-forth-namespace
|
|||||||
out: SD_MMC
|
out: SD_MMC
|
||||||
out: SD
|
out: SD
|
||||||
out: WiFi
|
out: WiFi
|
||||||
out: WebServer
|
|
||||||
out: Wire
|
out: Wire
|
||||||
out: ok
|
out: ok
|
||||||
check-esp32-basics
|
check-esp32-basics
|
||||||
|
|||||||
@ -25,18 +25,6 @@ transfer{
|
|||||||
}transfer
|
}transfer
|
||||||
forth definitions
|
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
|
vocabulary WiFi WiFi definitions
|
||||||
|
|
||||||
transfer{
|
transfer{
|
||||||
|
|||||||
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
static char filename[PATH_MAX];
|
static char filename[PATH_MAX];
|
||||||
|
|
||||||
#ifdef ENABLE_WEBSERVER_SUPPORT
|
|
||||||
static String string_value;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{{core}}
|
{{core}}
|
||||||
{{interp}}
|
{{interp}}
|
||||||
{{boot}}
|
{{boot}}
|
||||||
@ -53,24 +49,6 @@ static cell_t ResizeFile(cell_t fd, cell_t size) {
|
|||||||
return 0;
|
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
|
#ifdef ENABLE_INTERRUPTS_SUPPORT
|
||||||
struct handle_interrupt_args {
|
struct handle_interrupt_args {
|
||||||
cell_t xt;
|
cell_t xt;
|
||||||
|
|||||||
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
#ifndef SIM_PRINT_ONLY
|
#ifndef SIM_PRINT_ONLY
|
||||||
|
|
||||||
# ifdef ENABLE_WEBSERVER_SUPPORT
|
|
||||||
# include "WebServer.h"
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
@ -48,7 +44,6 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
OPTIONAL_SPIFFS_SUPPORT \
|
OPTIONAL_SPIFFS_SUPPORT \
|
||||||
OPTIONAL_WIFI_SUPPORT \
|
OPTIONAL_WIFI_SUPPORT \
|
||||||
OPTIONAL_MDNS_SUPPORT \
|
OPTIONAL_MDNS_SUPPORT \
|
||||||
OPTIONAL_WEBSERVER_SUPPORT \
|
|
||||||
OPTIONAL_SD_SUPPORT \
|
OPTIONAL_SD_SUPPORT \
|
||||||
OPTIONAL_SD_MMC_SUPPORT \
|
OPTIONAL_SD_MMC_SUPPORT \
|
||||||
OPTIONAL_I2C_SUPPORT \
|
OPTIONAL_I2C_SUPPORT \
|
||||||
@ -513,43 +508,6 @@ static cell_t FromIP(IPAddress ip) {
|
|||||||
X("MDNS.begin", MDNS_BEGIN, n0 = MDNS.begin(c0))
|
X("MDNS.begin", MDNS_BEGIN, n0 = MDNS.begin(c0))
|
||||||
#endif
|
#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
|
#ifndef ENABLE_OLED_SUPPORT
|
||||||
# define OPTIONAL_OLED_SUPPORT
|
# define OPTIONAL_OLED_SUPPORT
|
||||||
#else
|
#else
|
||||||
|
|||||||
20
ueforth/examples/httpd_sample.fs
Executable file
20
ueforth/examples/httpd_sample.fs
Executable 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
|
||||||
@ -45,7 +45,7 @@ sockaddr httpd-port sockaddr client variable client-len
|
|||||||
: server ( port -- )
|
: server ( port -- )
|
||||||
httpd-port ->port! ." Listening on port " httpd-port ->port@ . cr
|
httpd-port ->port! ." Listening on port " httpd-port ->port@ . cr
|
||||||
AF_INET SOCK_STREAM 0 socket to sockfd
|
AF_INET SOCK_STREAM 0 socket to sockfd
|
||||||
( sockfd SOL_SOCKET SO_REUSEADDR 1 >r rp@ 4 setsockopt rdrop throw )
|
( sockfd SOL_SOCKET SO_REUSEADDR 1 >r rp@ 4 setsockopt rdrop throw )
|
||||||
sockfd non-block throw
|
sockfd non-block throw
|
||||||
sockfd httpd-port sizeof(sockaddr_in) bind throw
|
sockfd httpd-port sizeof(sockaddr_in) bind throw
|
||||||
sockfd max-connections listen throw
|
sockfd max-connections listen throw
|
||||||
@ -80,14 +80,14 @@ variable goal variable goal#
|
|||||||
: path ( -- a n ) 0 bl skipover bl eat rot drop ;
|
: path ( -- a n ) 0 bl skipover bl eat rot drop ;
|
||||||
: send ( a n -- ) client-type ;
|
: send ( a n -- ) client-type ;
|
||||||
|
|
||||||
: response ( mime$ result$ status mime$ -- )
|
: response ( mime$ result$ status -- )
|
||||||
s" HTTP/1.0 " client-type <# #s #> client-type
|
s" HTTP/1.0 " client-type <# #s #> client-type
|
||||||
bl client-emit client-type client-cr
|
bl client-emit client-type client-cr
|
||||||
s" Content-type: " client-type client-type client-cr
|
s" Content-type: " client-type client-type client-cr
|
||||||
client-cr ;
|
client-cr ;
|
||||||
: ok-response ( mime$ -- ) s" OK" 200 response ;
|
: ok-response ( mime$ -- ) s" OK" 200 response ;
|
||||||
: bad-response ( mime$ -- ) s" text/plain" s" Bad Request" 400 response ;
|
: bad-response ( -- ) s" text/plain" s" Bad Request" 400 response ;
|
||||||
: notfound-response ( mime$ -- ) s" text/plain" s" Not Found" 404 response ;
|
: notfound-response ( -- ) s" text/plain" s" Not Found" 404 response ;
|
||||||
|
|
||||||
only forth definitions
|
only forth definitions
|
||||||
httpd
|
httpd
|
||||||
|
|||||||
@ -500,8 +500,9 @@ SPIFFS.totalBytes ( -- n )
|
|||||||
SPIFFS.usedBytes ( -- n )
|
SPIFFS.usedBytes ( -- n )
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h5>WebServer</h5>
|
<h5>WebServer (DEPRECATED)</h5>
|
||||||
These words are inside the <code>WebServer</code> vocabulary.
|
These words are inside the <code>WebServer</code> vocabulary.
|
||||||
|
<p><b>Removed in 7.0.6.14</b>, use httpd instead.</p>
|
||||||
<pre>
|
<pre>
|
||||||
WebServer.new ( port -- ws ) Allocate new webserver object
|
WebServer.new ( port -- ws ) Allocate new webserver object
|
||||||
WebServer.delete ( ws -- ) Delete webserver object
|
WebServer.delete ( ws -- ) Delete webserver object
|
||||||
@ -521,6 +522,45 @@ WebServer.sendContent ( z ws -- )
|
|||||||
WebServer.method ( ws -- n ) GET / POST etc.
|
WebServer.method ( ws -- n ) GET / POST etc.
|
||||||
</pre>
|
</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>
|
<h5>Wire</h5>
|
||||||
These words are inside the <code>Wire</code> vocabulary.
|
These words are inside the <code>Wire</code> vocabulary.
|
||||||
<pre>
|
<pre>
|
||||||
|
|||||||
Reference in New Issue
Block a user