Skip to content

solving for content-length request header #1110

@baywet

Description

@baywet

Hey @Ndiritu @calebkiage @andreaTP @ramsessanchez @araneolus @ffcdf (I'm probably missing others, feel free to mention them as well)
We're having conversations about the content-length all over the place, and I think this is not helping solving the issues for good.

Here are the different contexts where the content-length is critical from an HTTP standpoint:

  • When the length is known in advance (small payloads, large file upload implementation), it MUST be set.
  • When the length is NOT known in advance (streaming) it MUST NOT be set.

From there, we have a couple of additional requirements/constraints:

  • OkHttp will set the content-length header automatically, once the writeTo method is called on the body, depending on the media type and the stream type from what I can tell. But the rules are unclear.
  • Request information instances need to be able to override the Content-Length header (large file upload implementation mostly)
  • The content length value needs to be passed to the span attribute for tracing when it's available.

@andreaTP rightfully pointed out that we should not be using the available method since implementations behaviour vary. I think that part of the confusion here is that streams in dotnet behave a bit differently w.r.t. that aspect.

So one first step we probably need to take is to remove that if block body. (and yes, I know I'm the one who made that suggestion, maybe I should've taken more sick days)

I already fixed a regression to restore the default okhttp behaviour when the content length header is not overridden by the request in #1109 (maybe the code here needs to be updated to be a strict rather than lower or equal comparison, and set the initial value to -1)

This block most likely needs to be moved back to after the body is built because we won't get the native writeTo behaviour otherwise.


(but it needs to be tested thoroughly)

Finally, before merging any PRs further, and adding to the confusion, thorough integration end to end testing needs to be done for both large file upload and regular post with structured bodies as I pointed out. And to avoid any false negative/positive, it needs to be done in a way that all dependencies (kiota, graph core, graph) are locally linked all the way to the test project.

@araneolus nicely provided test code for ODSP LFU here, we need the same for Exchange LFU since the service-side behaviour differs a little from what I can remember.

Between medical down-time for the last couple of weeks, and upcoming travel for the next couple of weeks, I can't be the one handling this. I'm volunteering @Ndiritu , but of course we need to consider other priorities internally first.

I hope this recap was helpful in clarifying the confusion. Thank you everyone for the help, input, and feedback! Please call me out if any of my analysis points are incorrect, this is the starting point of a discussion to figure out what the required changes are.

Metadata

Metadata

Assignees

Labels

Standard GitHub labelIssue caused by core project dependency modules or librarybugSomething isn't working

Type

No type

Projects

Status

Done ✔️

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions