27 const char *path =
nullptr;
29 const char *dest =
nullptr;
35static UploadCtx s_upl;
38static bool upload_stream_begin(
HttpReq *req)
40 if (strcmp(req->
method,
"POST") != 0)
48 if (!s_upl.path || strcmp(req->
path, s_upl.path) != 0)
59 if (s_upl.fs && s_upl.dest)
61 s_upl.file = s_upl.fs->open(s_upl.dest,
"w");
76static void upload_stream_data(
HttpReq *req,
const uint8_t *data,
size_t len)
79 if (s_upl.active && !s_upl.error)
81 if (s_upl.file.write(data, len) != len)
93static void upload_handle(uint8_t slot_id,
HttpReq *req)
95 if (!req->body_streaming)
97 s_upl.server->send(slot_id, 400, PC_MIME_TEXT_PLAIN,
"POST a file body");
104 if (!s_upl.active || s_upl.error)
106 s_upl.server->send(slot_id, 500, PC_MIME_TEXT_PLAIN,
"upload failed");
110 pc_sb sb_msg = {msg,
sizeof(msg), 0,
true};
112 pc_sb_u32(&sb_msg, (uint32_t)((
unsigned)s_upl.written));
118 s_upl.server->send(slot_id, 200, PC_MIME_TEXT_PLAIN, msg);
121size_t pc_upload_last_size()
123 return s_upl.written;
126void pc_upload_begin(
PC &server,
const char *path, fs::FS &fs,
const char *dest_path)
128 s_upl.server = &server;
131 s_upl.dest = dest_path;
133 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.
Standalone HTTP/1.1 request parser - no transport dependency.
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
Layer 7 (Application) - public HTTP routing API.
@ HTTP_POST
Non-idempotent create / action.
Bounded no-heap string builder that fails closed on overflow (one shared copy).
size_t pc_sb_finish(pc_sb *b)
NUL-terminate and return the built length, or 0 if the build overflowed.
void pc_sb_put(pc_sb *b, const char *s)
Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.
void pc_sb_u32(pc_sb *b, uint32_t v)
Append v as decimal (no leading zeros; "0" for zero).
Fully-parsed HTTP/1.1 request.
char path[MAX_PATH_LEN]
URL path, null-terminated; no query string.
char method[PC_METHOD_BUF_SIZE]
HTTP method, null-terminated (OPTIONS, or WebDAV methods when enabled).
Bump-append target; ok latches false once an append would overflow cap.
Streaming file upload to an Arduino FS (PC_ENABLE_UPLOAD).