Moya: HTTP response headers from an RxMoya.Response object

Created on 26 Oct 2016  Â·  1Comment  Â·  Source: Moya/Moya

Not wanting to dupe #515 but is it possible to extract HTTP response headers from an RxMoya.Response object? The issue didn't seem to be adequately addressed there.

Cheers! 😄

question rxmoya

Most helpful comment

So it turns out that the RxMoya.Response value comes out of a request as an NSHTTPURLResponse, thus giving access to the HTTP headers:

(lldb) po (response.response as? NSHTTPURLResponse)?.allHeaderFields
â–¿ Optional<Dictionary<NSObject, AnyObject>>
  â–¿ Some : 15 elements
    â–¿ [0] : 2 elements
      - .0 : Content-Type
      - .1 : application/json; charset=utf-8
...

which is great. I didn't pick it up as the generated headers for the Moya framework show the RxMoya.Response value as being an NSURLResponse, as was pointed out in #515 .

Thanks either way! 😄

>All comments

So it turns out that the RxMoya.Response value comes out of a request as an NSHTTPURLResponse, thus giving access to the HTTP headers:

(lldb) po (response.response as? NSHTTPURLResponse)?.allHeaderFields
â–¿ Optional<Dictionary<NSObject, AnyObject>>
  â–¿ Some : 15 elements
    â–¿ [0] : 2 elements
      - .0 : Content-Type
      - .1 : application/json; charset=utf-8
...

which is great. I didn't pick it up as the generated headers for the Moya framework show the RxMoya.Response value as being an NSURLResponse, as was pointed out in #515 .

Thanks either way! 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

geraldeersteling picture geraldeersteling  Â·  3Comments

GurpalRajput picture GurpalRajput  Â·  3Comments

ghost picture ghost  Â·  3Comments

PlutusCat picture PlutusCat  Â·  3Comments

sunshinejr picture sunshinejr  Â·  3Comments