Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnableRewind option to AsString body extension #156

Open
jchannon opened this issue Jan 30, 2019 · 3 comments
Open

Add EnableRewind option to AsString body extension #156

jchannon opened this issue Jan 30, 2019 · 3 comments
Labels

Comments

@jchannon
Copy link
Member

@jchannon jchannon commented Jan 30, 2019

This will need to call 👍

 private static async Task PrepareRequestBody(HttpContext context)
        {
            if (!context.Request.Body.CanSeek)
            {
                context.Request.EnableBuffering();

                await context.Request.Body.DrainAsync(CancellationToken.None);
            }

            // Always start at the beginning.
            context.Request.Body.Seek(0L, SeekOrigin.Begin);
        }

Then read the body without a using statement in a StreamReader otherwise this closes the stream and it can't be read again therefore you'd need new StreamReader(stream).ReadToEndAsync()

@0x414c49
Copy link

@0x414c49 0x414c49 commented Mar 16, 2020

@jchannon the link you provided does not exist anymore.

@jchannon
Copy link
Member Author

@jchannon jchannon commented Mar 16, 2020

Ah its just a link to show how you could call AsString() which will have the code above in and then you could call Bind and it wouldn't fail as the body's position would be back at position 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.