Closed Davester47 closed 3 years ago
anonymous data is stored in req.fields[0]
curl -d "[1,2,3]" -H "Content-Type: application/json" -X POST http://localhost:3000/data
if (req.fieldsz) {
printf("raw: '%s'\n", req.fields[0].val);
printf("sanitized: '%s'\n", req.fields[0].parsed.s);
}
// raw: '[1,2,3]'
// sanitized: '[1,2,3]'
Thank you.
This is a very well written and easy to use library. I was just wondering whether it is possible to read the body of a request and not just key/value pairs using kreq.fields. Is there something similar to
khttp_write()
but for reading instead? I'm looking for something likekhttp_read()
. I'm trying to implement a REST api, and I need this feature. I couldn't find anything like it in the documentation.I noticed the khttp_parse.3 manpage mentioned that
khttp_parse
andkhttp_parsex
have the capability to read and validate key-value form data and opaque message bodies, but I didn't see anywhere that said how to access an opaque message body. Would an operation like this violate the sandboxing requirements?