WKWebView does not response correct MimeType in `decidePolicyForNavigationResponse`

I want to detect the response MimeType so that accordingly handle the type of file that's being downloaded. So, for example, if the file type is `application/vnd.ms-excel` then I want to take certain action but, with WKWebView it is always returning `text/html` in `-(void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler`


I noticed that if I debug the WKWebView using Safari then the response MimeType is correctly displaying as `application/vnd.ms-excel` but, maybe because of QuickLook feature available in WkWebView the content is getting converted into HTML and responding `text/html`.


Is there any way to detect the mimeType apart from the above option that returns the actual file's mimeType?

The headers on the response are available in decidePolicyForNavigationResponse by casting the navigationResponse.response as (NSHTTPURLResponse *). And then taking a look at allHeaderFields. You should be able to see the Content-Type header in this way.


NSDictionary *HTTPResponseHeaders = ((NSHTTPURLResponse *)navigationResponse.response).allHeaderFields;



Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

WKWebView does not response correct MimeType in `decidePolicyForNavigationResponse`
 
 
Q