Code Monkey home page Code Monkey logo

Comments (5)

Asmod4n avatar Asmod4n commented on July 29, 2024 1

The rsize argument holds the actual length of what was decoded.
You have to limit printf by that size.

from picohttpparser.

bharatkrishna avatar bharatkrishna commented on July 29, 2024

A rough flow of my program(in pseudo C code):

rv = read(sock, buf, 4096);
phr_parse_response(...); /* I check the headers after this and set chunked_response = 1 if headers indicate */
if (chunked_response) {
    size = rv /* setting this to offset buffer with what has been read so far */
    do {
        while ((rret = read(sock, buf + size, capacity - size)) == -1 && errno == EINTR)
            ;
        if (rret <= 0)
            return IOError;
        /* decode */
        rsize = rret;
        pret = phr_decode_chunked(&decoder, buf + size, &rsize);
        if (pret == -1)
            return ParseError;
        size += rsize;
    } while (pret == -2);
}
printf("%s", buf); /* prints the output shown above */

from picohttpparser.

bharatkrishna avatar bharatkrishna commented on July 29, 2024

I am adding rsize of each decode to size. So I should limit it by size to print the whole buffer?

from picohttpparser.

Asmod4n avatar Asmod4n commented on July 29, 2024

I would guess so, yes.
Where i am using it i simply cut off the buffer each time i use phr_decode_chunked.

from picohttpparser.

bharatkrishna avatar bharatkrishna commented on July 29, 2024

Thanks. When I limit the printf by the size, it prints the decoded chunks correctly.

from picohttpparser.

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.