Comments (2)
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)
- Headers lost on a Partial parse HOT 1
- HTTP POST Request Example HOT 1
- expose static Error str
- tests fail to build with --no-default-features.
- How get a header value easily ?
- A way to ignore headers completely HOT 2
- Comment for Request.version doesn't make sense
- Add an option to get the body out of request HOT 2
- Should Line Folding get replaced by spaces? HOT 2
- Please increase the demo number of headers HOT 3
- Parse from noncontiguous byte slices? HOT 5
- Allow providing a list of expected headers HOT 1
- Improve error message on invalid request start-line
- double quotes in headers can not be parsed HOT 3
- Benchmark is not an apples to apples comparison (sse4.2) HOT 8
- Allow " in URIs HOT 3
- Allow spaces between header names and colons HOT 5
- README is outdated HOT 1
- Need for `Request` to take a slice of `MaybeUninit<Header>` HOT 2
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 httparse.