11#if DETWS_ENABLE_UPLOAD
26 const char *path =
nullptr;
28 const char *dest =
nullptr;
34static UploadCtx s_upl;
37static bool upload_stream_begin(
HttpReq *req)
39 if (strcmp(req->
method,
"POST") != 0)
41 if (!s_upl.path || strcmp(req->
path, s_upl.path) != 0)
47 if (s_upl.fs && s_upl.dest)
49 s_upl.file = s_upl.fs->open(s_upl.dest,
"w");
60static void upload_stream_data(
HttpReq *req,
const uint8_t *data,
size_t len)
63 if (s_upl.active && !s_upl.error)
65 if (s_upl.file.write(data, len) != len)
73static void upload_handle(uint8_t slot_id,
HttpReq *req)
75 if (!req->body_streaming)
77 s_upl.server->send(slot_id, 400, DET_MIME_TEXT_PLAIN,
"POST a file body");
82 if (!s_upl.active || s_upl.error)
84 s_upl.server->send(slot_id, 500, DET_MIME_TEXT_PLAIN,
"upload failed");
88 snprintf(msg,
sizeof(msg),
"OK %u bytes", (
unsigned)s_upl.written);
89 s_upl.server->send(slot_id, 200, DET_MIME_TEXT_PLAIN, msg);
92size_t detws_upload_last_size()
97void detws_upload_begin(
DetWebServer &server,
const char *path, fs::FS &fs,
const char *dest_path)
99 s_upl.server = &server;
102 s_upl.dest = dest_path;
104 http_parser_set_stream_hooks(upload_stream_begin, upload_stream_data);
Single-port HTTP server with deterministic, zero-allocation execution.
void on(const char *path, HttpMethod method, Handler callback)
Register a route handler.
Layer 7 (Application) - public HTTP routing API.
@ HTTP_POST
Non-idempotent create / action.
Standalone HTTP/1.1 request parser - no transport dependency.
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
Fully-parsed HTTP/1.1 request.
char method[DETWS_METHOD_BUF_SIZE]
HTTP method, null-terminated (OPTIONS, or WebDAV methods when enabled).
char path[MAX_PATH_LEN]
URL path, null-terminated; no query string.
Streaming file upload to an Arduino FS (DETWS_ENABLE_UPLOAD).