nekipelov / httpparser

HTTP request, response and urls parser
MIT License
118 stars 36 forks source link

missing major parametrs parsing #3

Closed marriusco closed 2 years ago

marriusco commented 4 years ago

Hi, This is missing parameters extaraction http://localhost/?param1=value&param2=val theu all got part of uri....

nekipelov commented 4 years ago

Can you describe your problem in more detail? With an example.

ghost commented 4 years ago

a request like http://localhost/?abc=def&some=5 get's the request.uri having /?abc=def&some=5'. The uri is just the / and the rest are eparameters The uri should be / and abc=def and some=5 should be in a map as the headers are as key=value

Also a basic authentication format does not get's parsed at all http://username:password@example.com/

nekipelov commented 4 years ago

If you want to parse url, use UrlParser (https://github.com/nekipelov/httpparser/blob/master/examples/urlparser.cpp).

You want to parse URI from http request, you need something like this: https://gist.github.com/nekipelov/9dd560d8880751b70c3c95cb348d38d4. ⚠️Warning: very old code :-)

About basic authentication see https://www.ietf.org/rfc/rfc2617.txt.

ghost commented 4 years ago

GET /index.page?a=b&c=d&e=f HTTP/1.1 Host: localhost:8888 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 Accept-Language: en-CA,en-US;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive Upgrade-Insecure-Requests: 1

How I access the a c and e ? What I am doing wrong ?

nekipelov commented 4 years ago
{
    const char text[] = "GET /index.page?a=b&c=d&e=f HTTP/1.1\r\n"
                        "Host: localhost:8888\r\n"
                        "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0\r\n"
                        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8\r\n"
                        "Accept-Language: en-CA,en-US;q=0.7,en;q=0.3\r\n"
                        "Accept-Encoding: gzip, deflate\r\n"
                        "Connection: keep-alive\r\n"
                        "Upgrade-Insecure-Requests: 1\r\n"
                        "\r\n";

    using namespace httpparser;

    Request request;
    HttpRequestParser parser;

    HttpRequestParser::ParseResult res = parser.parse(request, text, text + strlen(text));

    if( res == HttpRequestParser::ParsingCompleted )
    {
        Params params;
        parseQueryString(params, request.uri);

        std::cout << "\ta: " << params["a"] << "\n";
        std::cout << "\tc: " << params["c"] << "\n";
        std::cout << "\te: " << params["e"] << "\n";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

See https://gist.github.com/nekipelov/9dd560d8880751b70c3c95cb348d38d4.

ghost commented 4 years ago

Thank you. I did not spot that. Appreciate.

On Wed, Apr 29, 2020 at 3:08 PM Alex Nekipelov notifications@github.com wrote:

{ const char text[] = "GET /index.page?a=b&c=d&e=f HTTP/1.1\r\n" "Host: localhost:8888\r\n" "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0\r\n" "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8\r\n" "Accept-Language: en-CA,en-US;q=0.7,en;q=0.3\r\n" "Accept-Encoding: gzip, deflate\r\n" "Connection: keep-alive\r\n" "Upgrade-Insecure-Requests: 1\r\n" "\r\n";

using namespace httpparser;

Request request;
HttpRequestParser parser;

HttpRequestParser::ParseResult res = parser.parse(request, text, text + strlen(text));

if( res == HttpRequestParser::ParsingCompleted )
{
    Params params;
    parseQueryString(params, request.uri);

    std::cout << "\ta: " << params["a"] << "\n";
    std::cout << "\tc: " << params["c"] << "\n";
    std::cout << "\te: " << params["e"] << "\n";

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

See https://gist.github.com/nekipelov/9dd560d8880751b70c3c95cb348d38d4.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nekipelov/httpparser/issues/3#issuecomment-621405851, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB5PRAO25CNETR2LEXA6X3TRPB3MXANCNFSM4MTLKRCQ .