62static __declspec(thread)
struct kreq *g_kcgi_req = NULL;
64static __thread
struct kreq *g_kcgi_req = NULL;
85static Value kcgi_fields_to_map(
const struct kreq *r) {
88 for (
size_t i = 0; i < r->fieldsz; i++) {
89 const char *k = r->fields[i].key ? r->fields[i].key :
"";
90 const char *v = r->fields[i].val ? r->fields[i].val :
"";
112static Value kreq_to_fun(
const struct kreq *r) {
121 Value fields = kcgi_fields_to_map(r);
122 map_set(&out,
"fields", fields);
145static int kcgi_parse_request(
struct kreq **out) {
146 static const struct kvalid keys[] = { { NULL, NULL } };
147 struct kreq *r = (
struct kreq *)calloc(1,
sizeof(*r));
149 enum kcgi_err er = khttp_parse(r, keys, 0, NULL, 0, 0);
150 if (er != KCGI_OK) { free(r);
return 0; }
162static void kcgi_free_request(
struct kreq *r) {
183static int kcgi_reply_start(
int code,
const char *ctype) {
184 if (!g_kcgi_req)
return 0;
186 if (ctype && *ctype) {
187 if (khttp_head(g_kcgi_req,
"Content-Type",
"%s", ctype) != KCGI_OK)
190 if (khttp_body(g_kcgi_req) != KCGI_OK)
204static int kcgi_write_str(
const char *s) {
205 if (!g_kcgi_req)
return 0;
207 size_t n = strlen(s);
208 return khttp_write(g_kcgi_req, s, n) == KCGI_OK;
int map_set(Value *vm, const char *key, Value v)
Insert or replace a key in the map.
Value make_map_empty(void)
Construct a new empty map Value.
Tagged union representing a Fun value.
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.