Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

[HttpServer] Capturing body content #137

Open
avanderhoorn opened this issue Dec 28, 2016 · 5 comments
Open

[HttpServer] Capturing body content #137

avanderhoorn opened this issue Dec 28, 2016 · 5 comments
Labels

Comments

@avanderhoorn
Copy link
Member

Body data can only be ready once, hence when we go to read it we will need to wrap the body stream that already exists. This means that from that point onwards, if anyone interacts with the body stream they will be using our copy (the Req/Res objects have a setter for the Body so this should be fine.

Next we need to attempt to read the stream to completion or till we have hit our trim limit (62k - this is a limit that we define so that we don't end up reading 100's mbs). With what ever data we read, we return as part of our payload, but we also need to keep a Memory Stream copy of it so that when someone else attempts to read the Body later we can given them that copy. Only slight trick is that if we only partially read the result previously, we will need to drain our Memory Stream copy first before switching back to the original Body stream.

Note, we also need to be content type/encoding aware as there isn't any point trimming binary content.

@khellang
Copy link

khellang commented Dec 28, 2016

Can't you use the EnableRewind functionality on the request for this? That should take care of buffering and potentially spool to a temp file is the body is big enough.

@avanderhoorn
Copy link
Member Author

Ya I thought about that, but EnableRewind has the potential side effect of writing to the filesystem. For our scenario, I'm wondering if we can do something similar (by way of how the stream is wrapped) and do it without writing to the filesystem as we only have to do a partial read of the content is too long... does that make sense?

@avanderhoorn
Copy link
Member Author

I was talking to @davidfowl and the side effects of EnableRewind is probably acceptable. Other tools will also use this so its going to be fine for now.

@khellang
Copy link

If you only do a partial read (less than the threshold), the bytes never touch disk anyway. You only want the buffering part so you can rewind the stream after you're finished reading what you need. 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants