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

"Prefer" request header in PageIterator #2731

Open
WolfgangHG opened this issue Nov 1, 2024 · 2 comments
Open

"Prefer" request header in PageIterator #2731

WolfgangHG opened this issue Nov 1, 2024 · 2 comments

Comments

@WolfgangHG
Copy link

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.

@WolfgangHG WolfgangHG added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Nov 1, 2024
@andrueastman
Copy link
Member

Thanks for raising this @WolfgangHG

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.

I believe TCollectionPage is typically a model that has a property with the nextlink (only the url that the iterator follows) as well as a List<T> of the individual response items. As the first request is made outside of the context of the PageIterator using the requestConfigurator parameter is what would be expected for now.

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close Question: SDK and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Feb 4, 2025
@WolfgangHG
Copy link
Author

@andrueastman You can close this if you think the current behavior is valid. I just wanted to bring it to your attention - it confused me a bit ;-). It would be helpful if the api could detect that only the first iterator page has a requestConfiguration and throw an exception.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Feb 4, 2025
@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants