HttpContextAccessor.HttpContext is not populated for $batch subrequests
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Problem Statement
If HttpContextAccessor is used to try and access the HttpContext inside any of the subrequests of a $batch request, the HttpContext is null.
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 null for both subrequests.
- You can make a non-$batch request to validate the opposite where a single regular request to an endpoint does have a valid HttpContext (make a
GETrequest tohttp://localhost:5000/api/Students('0001'))
What is expected
We would expect the HttpContextAccessor.HttpContext value to be populated with the HttpContext for the current subrequest.
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
Run the ODataBatchHttpContext service from the linked proof of concept and reproduce the POST to /api/$batch. Start at the StudentsController demonstration and the $batch request handling entry point; done means HttpContextAccessor.HttpContext is populated for each subrequest while regular requests continue to work.
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
- 35/100