[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Beginners' question: multi-threaded HTTP service
On 2012-11-19 21:59, Mark Ellzey wrote:
> On Mon, Nov 19, 2012 at 10:12:53PM +0200, Nir Soffer wrote:
>> On Mon, Nov 19, 2012 at 7:26 PM, Pander <pander@xxxxxxxxxxxxxxxxxxxxx>wrote:
>>
>>> Second question is regarding buffer_in in request. I can't seem to find
>>> a proper example with helpers to retrieve the POST parameters.
>>
>>
>> If you want to support the default form encoding
>> (application/x-www-form-urlencoded),
>> you can use evhttp_parse_query_str().
>>
>> libevent does not have any code to parse multipart/form-data.
>
> Hmm, think he's talking about evhtp, not evhttp.
>
>
> The evhtp_request_t structure contains the evhtp_uri_t structure which
> tries to maintain the proper tree-format of a URI:
>
> uri ->
> authority ->
> username
> password
> hostname
> port
> path ->
> full path (/a/b/c.html)
> path (/a/b/)
> file (index.html)
> fragment ->
> data after '#' in the query
> scheme ->
> the scheme of the request if found
> query ->
> a evhtp_kv_t list of query keys and values
>
>
> You can get the raw query arguments by using
>
> request->uri->query_raw
is NULL :( as is query, fragment and path
> or you can access the parsed query arguments via this:
>
> request->uri->query
>
> by either looking for specific values:
>
> const char * val = evhtp_kv_find(request->uri->query, "key");
>
> Or by iterating over each one:
>
> int my_callback(evhtp_kv_t * kv, void * arg) {
> printf("key=%s val=%s\n", kv->key, kv->val);
> return 0;
> }
>
> evhtp_kvs_for_each(request->uri->query, my_callback, NULL);
segfaults :(
only this works:
char buf[1024];
int n;
while ((n = evbuffer_remove(req->buffer_in, buf, sizeof(buf))) > 0) {
fwrite(buf, 1, n, stdout);
}
printf("\n");
or this:
int max_len = 1024
int len = evbuffer_get_length(req->buffer_in);
if (len == 0 || len >= max_len) {
return;
}
char buf[max_len];
evbuffer_remove(req->buffer_in, buf, len);
buf[len] = '\0';
printf("%s\n", buf);
> ***********************************************************************
> To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> unsubscribe libevent-users in the body.
>
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.