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

document the use of the headersinspection handler and the options. #90

Open
andrueastman opened this issue May 13, 2024 · 4 comments
Open

Comments

@andrueastman
Copy link
Contributor

Related to microsoft/kiota#2963

We should add samples of reading request/response headers in the languages supported.

In C# this looks to be close to

            var headersInspectionHandlerOption = new HeadersInspectionHandlerOption()
            {
                InspectResponseHeaders = true // specific you wish to collect reponse headers
            };
            //add the option
            var user = graphClient.Users["user-id"].GetAsync(requestConfiguration => requestConfiguration.Options.Add(headersInspectionHandlerOption));
            //use the key to get the header.
            var locationHeader = headersInspectionHandlerOption.ResponseHeaders["Location"];
@frizat82
Copy link

Is there a way to make a custom request with that Location URL that is returned? We'd want the Auth passed from the existing graphClient - but i don't see a way to make a custom request - i'd have to create a new HttpClient which is duplicative.

@baywet baywet moved this from Needs Triage 🔍 to Todo 📃 in Kiota May 22, 2024
@demian-licht-hs
Copy link

Piggybacking here, in python it would be something like:

from kiota_http.middleware import HeadersInspectionHandler

headers_handler = HeadersInspectionHandler()

and then after the request is made, you can get, say, the location from the response headers as such:

headers_handler.options._response_headers._headers['location']

@rm-code
Copy link

rm-code commented Jun 17, 2024

@andrueastman I've just tried your code in a csharp project and must be missing something, because both the ResponseHeaders and RequestHeaders are empty after the request result is returned.

Are there additional steps when creating the client with kiota to enable the header-inspection functionality?

@jesshannon
Copy link

@rm-code if you customised the DI setup you may have missed registering the HeadersInspectionHandler like I did.

AddHttpClient().AddHttpMessageHandler(() => new HeadersInspectionHandler())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants