microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

"Prefer" request header in PageIterator

Open
#2,731 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs: Attention :wave: Question: SDK
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

You can create a request that fetches a calendar item content as plain text like this:

EventCollectionResponse eventCollResponse = await graphClient.Me.Calendar.Events.GetAsync(
  c =>
  {
    c.Headers.Add("Prefer", "outlook.body-content-type=\"text\"");
  });

You could put this response object in an iterator:

PageIterator<Event, EventCollectionResponse> iterator = PageIterator<Event, EventCollectionResponse>.CreatePageIterator(graphClient, eventCollResponse,
  (eventAktuell) =>
  {
    //Do something....
    return true;
  });

But there, the "Prefer" header is only applied to the first page, the rest of the calendar items returns the html body.

Solution/Workaround: set the header in the iterator instead:

PageIterator<Event, EventCollectionResponse> iterator = PageIterator<Event, EventCollectionResponse>.CreatePageIterator(graphClient, eventCollResponse,
  (eventAktuell) =>
  {
    //Do something....
    return true;
  },
  c =>
  {
    c.Headers.Add("Prefer", "outlook.body-content-type=\"text\"");
  }));

One might expect that the header for the initial request is applied to all pages of the iterator.

What do you think? Is the current behavior expected, or is this something that could be improved? It could either copy headers from the "TCollectionPage" to each page request. Or it could also raise an exception if the "TCollectionPage" contains headers instead of providing them to the iterator itself, as it probably has unexpected results if using it this way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at PageIterator.CreatePageIterator and trace how subsequent page requests are built, using the reported Prefer header behavior as the reproduction case. The issue presents two possible improvements rather than a settled expected behavior, so completion depends on deciding whether headers from the initial response should be propagated or rejected and verifying that behavior across iterator pages.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.