iOS get HTTP header from response

How to extract HTTP headers from GraphQLResult?

Hi @denys-meloshyn, I don’t believe there is a way to get it directly from a GraphQLResult since that will have all the transport details stripped away already. You will probably need to implement a custom interceptor and inject that into the request chain - see our docs for guidance on how to do that.

Hi @calvincestari, thanks for quick reply. I looked already at Interceptors, I can extract all headers on that level but I have some doubts how to pass it further to GraphQLResult.

I can do smith like this, but extensions is not mutable plus I’m not sure this is correct to store it there

chain.proceedAsync(request: request,
                           response: response) { result in
            switch result {
            case .success(let data):
                var res = data
                res.extensions = response?.httpResponse.allHeaderFields
            case .failure(let error):

As an option I can store in a separate storage response?.httpResponse.allHeaderFields using request.contextIdentifier key and then in resultHandler try to extract it, but it doesn’t looks very nice :thinking:

GraphQLResult.extensions can only be used in the initializer. If you look in GraphQLResponse you can see where it provides the extensions object. That in turn is provided by the default JSONResponseParsingInterceptor.

I haven’t tried to do this before but it looks like you might need to provide your own JSON parsing interceptor or somehow inject it into the HTTPResponse.rawData before the default JSONResponseParsingInterceptor which will then get used by the existing code.