[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Beginners' question: multi-threaded HTTP service



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

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);


***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.