Comments (6)
New programs should not be using request->uri, or any of the other fields in request, directly; they should instead use the evhttp_request_get_* accessor functions.
That said, evhttp_request_get_uri is still a bad name. We should make sure that there exist functions that do the right thing, and we should make sure that the badness of the bad name.
evhttp_request_get_evhttp_uri is supposed to be the function that does the right thing (when combined with the evhttp_uri accessors). This does need getter documentation though.
Renaming evhttp_request_get_uri is not a live option: we try to NEVER introduce changes that will break existing programs that use the API correctly.
from libevent.
Thanks for the quick response, but your response doesn't address my bug. evhttp_request_get_uri() still returns a part of the path, and so evhttp_find_header's first key value is corrupt. This is the code i have to use to fix the [query] part of the URI:
query=evhttp_request_get_uri(req);
//Find the query part of the URI.
query=strstr(query,"?")+1;
if(query<=1){
query=evhttp_request_get_uri(req);
}
evhttp_parse_query_str(query, &GET);
info_hash = (char *)evhttp_find_header(&GET, "key");
from libevent.
To make sure I understand, is there a reason you can't just do the preferred approach, which is:
const struct evhttp_uri *uri = evhttp_request_get_evhttp_uri(req);
query = evhttp_uri_get_query(uri);
evhttp_parse_query_str(query, &GET);
?
from libevent.
Thanks, that works, but very unexpectedly. In general I find this interface to be unnatural. For example why do i use a find_header() function for non-http-header elements like GET and POST? Getting the user's IP address is also strange:
evhttp_connection_get_peer(req->evcon,
&client_ip,
&scoket_client_port);
I think qdecoder has a nice and regular interface:
http://www.qdecoder.org/wiki/qdecoder
The difference is that the request struct is the mother argument for all accessor functions. Ideally you would just have to free the request struct, i.e. evhttp_request_free(req), at it would appropriately tear down all of the accessed data.
I like PHP's $_GET, $_POST, $_COOKIE, $_SERVER hash table system a lot. I should just be able to say:
char * key = evhttp_get_var(req, "key");
char * key = evhttp_post_var(req, "key");
char * proxy = evhttp_server_var(req, "x-forwarded-for");
from libevent.
I went ahead and ported libevhtp's query parser over to use evkeyvalq
. You can cut & paste the code into yours here: https://gist.github.com/ellzey/5060433
from libevent.
Oh neat, I already responded to this. The above is old, you can check out libevhtp's version, it's actually faster now.
I'm closing this since we plan on merging evhtp with evhttp in the alpha.
from libevent.
Related Issues (20)
- question about `bufferevent_filter_new` and `bufferevent_getcb` HOT 1
- stack-buffer-overflow at evutil_parse_sockaddr_port HOT 15
- HTTP Server sample fails to compile for Windows x64
- feature request: websocket api including client and server
- bufferevent_replacefd close socket when bufferevent‘s socket fd is eq new fd HOT 3
- The callback of evsignal SIGUSR1 Can't be called HOT 1
- Privacy Manifest file for iOS HOT 5
- 📚 Where is documentation? HOT 4
- WSOptions enum value bug
- Potential NULL pointer dereference HOT 1
- Potential Null dereference in test-dumpevents.c HOT 1
- Potential Null pointer dereference in bufferevent_openssl.c HOT 1
- Potential Null pointer dereference in regress_ws.c HOT 1
- Potential Null pointer dereference in time-test.c HOT 1
- Failure making HTTP request to unix socket HOT 2
- Coverage report is broken
- Undefined symbols for architecture after building libevent HOT 2
- libevent for iOS HOT 8
- MacOS CI is broken HOT 7
- event_process_active_single_queue: Use of memory after it is freed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libevent.