Git Product home page Git Product logo

Comments (2)

jkarneges avatar jkarneges commented on August 27, 2024

Following up on this. I came up with three possible solutions:

  • Parse the request twice, once before reading the body and once after. This is likely the simplest approach.

  • Keep doing the slice->index conversion thing we were doing, but take into account that a slice might not be in the buffer. Each tracked field could be an enum, something like enum FieldRef { RangeInBuf(u32, u32), Slice(&'static str) }. This is likely the closest solution to what we were already doing.

  • Use a different buffer for subsequent reads. After parsing the request, copy any remaining bytes into a second buffer, and then start using that second buffer for reading the body. The original buffer stays borrowed by the Request. Further, when it's time to read the next request, read it from the second buffer. This is likely the most optimal solution, if there happens to be an unused buffer lying around. In our case we did have this: an idle write buffer.

I ended up going with the last approach. For each connection we were allocating two Vec<u8> buffers, one for reading and one for writing, but the write buffer was not used at all during the reading process and so it was available. The implementation was a bit tricky, with the buffers switching places for each request, but it seems to work.

from httparse.

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.