MicrosoftDocs / openapi-docs

Creative Commons Attribution 4.0 International
13 stars 34 forks source link

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

Open andrueastman opened 6 months ago

andrueastman commented 6 months ago

Related to https://github.com/microsoft/kiota/issues/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 commented 6 months ago

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.

demian-licht-hs commented 5 months ago

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 commented 5 months ago

@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?