Artifact db771e1cdab7d76a97d8a9ad2e90e5e4696736e022fbf37de858d50ac240e569:
- File
src/http.h
— part of check-in
[da4167d308]
at
2026-11-23 14:34:25
on branch rc-screen
— /rc: one step to the phone, like Claude Code's /remote-control
With a phone paired, /rc turns remote control on and shows a short panel: whether it is on and connected, this conversation's link for the phone page (/#s=JOURNAL/SESSION, &c=PHONE when one phone is paired) and a QR code of it, and the paired phones; c copies the link, s turns it off or on, p pairs another. With no phone paired, /rc goes straight to pairing; Esc there returns to the conversation. remote.invite is named only when pairing fails without it.
ssh leaves the main screen: /rc ssh and pic rc --ssh show the ssh command and its checks as text, with no QR code. pic rc prints the phone's link and its QR code, pic rc --link the link alone.
The footer says "remote on" while pic remote is connected (checked every 10 s), as Claude Code shows "/rc active".
Fixes: pic remote marks its stream connected on the relay's 200 (http.c's new on_head callback) rather than on the first body byte, so /rc no longer says "connecting" for up to 15 s; after pairing /rc no longer tells you to run pic remote when it already runs.
Tests: test/tui/rc.sh (fake relay and phone: unpaired pairing screen, invite, paired link and QR, connected at once with a quiet relay, footer marker, s, pic rc, pic rc --ssh, /rc ssh); http's on_head; tui.sh, grapevine.sh and remote.sh updated for the new screens. (user: dmestas, size: 3562) [annotate] [blame] [check-ins using] [more...]
/* HTTP/1.1 for one POST per connection. The response parser is a pure * function over bytes (status line, headers, then a body delimited by chunked * encoding, Content-Length or the end of the connection), so it is fuzzed on * its own. */ #ifndef PIC_HTTP_H #define PIC_HTTP_H #include <stddef.h> #include "net.h" /* Body bytes as they arrive. Nonzero stops the response; feed returns it. */ typedef int (*pic_http_body_fn)(void *ctx, const char *bytes, size_t n); typedef struct pic_http_resp pic_http_resp; /* The final response's headers are in (R's status and headers set), before any body byte. * Nonzero stops the response; feed returns it. */ typedef int (*pic_http_head_fn)(void *ctx, const pic_http_resp *r); struct pic_http_resp { int state; /* internal */ int status; /* final status code, once headers are done */ char retry_after[32]; /* Retry-After value, if any */ char request_id[128]; /* request-id header, if any */ char content_type[128]; /* Content-Type, if any */ char etag[128]; /* ETag, if any */ char last_modified[64]; /* Last-Modified, if any */ char peer[8]; /* Pic-Peer, if any (remote control's relay) */ /* The rate-limit headers (every one whose name has "ratelimit" in it, * the vendors' prefixes alike), one "name: value" line each, the name * lowercased; what does not fit is dropped whole. */ char ratelimit[1024]; pic_http_body_fn on_body; pic_http_head_fn on_head; /* NULL unless set after pic_http_resp_init; gets ctx too */ void *ctx; char line[8192]; size_t line_len; size_t header_bytes; unsigned long long remaining; /* bytes left of the body or chunk */ int chunked, has_length, body_started; char err[160]; }; void pic_http_resp_init(pic_http_resp *r, pic_http_body_fn on_body, void *ctx); /* 0, a callback's nonzero value, or -1 on a malformed response (r->err). */ int pic_http_feed(pic_http_resp *r, const char *bytes, size_t n); /* 1 once the body is complete (more bytes are an error). */ int pic_http_done(const pic_http_resp *r); /* At the end of the connection: 0 if the response was complete, else -1. */ int pic_http_end(pic_http_resp *r); /* POSTs body to url (https://host[:port]/path, or http:// to loopback only) * with extra header lines ("Name: value"; a Content-Type among them replaces * the default application/json), streaming the response body to * r's callback. Header values are never copied into errors. 0 when a full * response arrived (any status), -1 on a transport or protocol failure with * err set. pic_net_tls_failed(net) then tells a TLS failure from others. */ int pic_http_post(pic_net *net, const char *url, const char *const *headers, size_t nheaders, const char *body, size_t body_len, pic_http_resp *r, int idle_seconds, int deadline_seconds, char *err, size_t errcap); /* GETs url, as pic_http_post does otherwise (no body). */ int pic_http_get(pic_net *net, const char *url, const char *const *headers, size_t nheaders, pic_http_resp *r, int idle_seconds, int deadline_seconds, char *err, size_t errcap); /* Any METHOD (PUT, DELETE), with BODY (NULL: none, no Content-Length) as pic_http_post. */ int pic_http_request(pic_net *net, const char *method, const char *url, const char *const *headers, size_t nheaders, const char *body, size_t body_len, pic_http_resp *r, int idle_seconds, int deadline_seconds, char *err, size_t errcap); #endif