HttpContextAccessor.HttpContext for a $batch request becomes unset after returning from ODataBatchMiddleware
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
(Related to Issue #230 )
Problem Statement
In any middleware that is in the pipeline above the ODataBatchMiddleware HttpContextAccessor.HttpContext will be populated before the request is passed onto the batch middleware but will be unset after returning from the batch middleware. We expect the HttpContextAccessor.HttpContext to be populated at all times.
How to reproduce
We have a minimal proof-of-concept example set up here to demonstrate this issue (you can just pull the project and build to the solution to test, no other dependencies required). Please ping me if you have an issue accessing this. The particular point of demonstration is here.
- Clone to repository
- Open the .sln and run the
ODataBatchHttpContextservice - Make the following $batch request against the service (using ARC/Postman/Fiddler etc.)
URI:
POST http://localhost:5000/api/$batch
Headers:
Content-Type: multipart/mixed; boundary=batch_aaf78fdf-f309-4c1d-ab0f-3c317770e5c6
Body:
--batch_aaf78fdf-f309-4c1d-ab0f-3c317770e5c6
Content-Type: application/http
Content-Transfer-Encoding: binary
GET http://localhost:5000/api/Students('0001') HTTP/1.1
OData-MaxVersion: 4.0
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
User-Agent: Microsoft.OData.Client/6.16.0
--batch_aaf78fdf-f309-4c1d-ab0f-3c317770e5c6
Content-Type: application/http
Content-Transfer-Encoding: binary
GET http://localhost:5000/api/Students('0002') HTTP/1.1
OData-MaxVersion: 4.0
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
User-Agent: Microsoft.OData.Client/6.16.0
--batch_aaf78fdf-f309-4c1d-ab0f-3c317770e5c6--
- After making the above request, you will see output printed in the console window for the service indicating the HttpContext was not null in the middleware at first but then becomes null afterwards.
What is expected
We would expect the HttpContextAccessor.HttpContext value to be populated with the HttpContext for the OData $batch request in both places.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked ODataBatchHttpContext proof of concept and inspect Middleware/BeforeBatchHandlerMiddleware.cs alongside ODataBatchMiddleware behavior. Reproduce the POST $batch request and trace HttpContextAccessor.HttpContext before and after the batch middleware. Done means the accessor remains populated in both locations, with regression coverage for the demonstrated request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100