Coder Social home page Coder Social logo

Comments (6)

nmathewson avatar nmathewson commented on June 22, 2024

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.

TheRook avatar TheRook commented on June 22, 2024

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.

nmathewson avatar nmathewson commented on June 22, 2024

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.

TheRook avatar TheRook commented on June 22, 2024

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.

errzey avatar errzey commented on June 22, 2024

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.

errzey avatar errzey commented on June 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.