Bug 203302 - WKWebView: WKURLSchemeHandler request don't have Range headers
Summary: WKWebView: WKURLSchemeHandler request don't have Range headers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: Other
Hardware: iPhone / iPad All
: P2 Major
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-10-23 10:30 PDT by jcesarmobile
Modified: 2021-05-03 15:53 PDT (History)
12 users (show)

See Also:


Attachments
Patch (2.47 KB, patch)
2019-10-23 17:27 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (6.31 KB, patch)
2021-04-30 15:34 PDT, Alex Christensen
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (6.34 KB, patch)
2021-04-30 15:51 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (6.39 KB, patch)
2021-05-03 12:46 PDT, Alex Christensen
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jcesarmobile 2019-10-23 10:30:02 PDT
The problem:
When serving an Apache Cordova or Ionic Capacitor app from a custom scheme, if the app contains a video tag, it makes multiple requests to the video file (I guess it's to return the video in chunks).
The problem is, the requests don't include Range headers, so it's impossible to return just the chunks, and also, as it's requested multiple times, the memory increases a lot.

Expected:

When using a WKURLSchemeHandler, the requests should include Range headers so the video can be returned by the requested chunks.
Alternatively, if the app is being served from a custom scheme, then a single request should be made to the WKURLSchemeHandler (when serving the app from file:// protocol only a request is made)


Sample project reproducing the issue (without using Apache Cordova nor Ionic Capacitor to simplify the code)

https://github.com/jcesarmobile/no-ranges-bug

Check the WebViewHandler class, it prints urlSchemeTask.request.allHTTPHeaderFields content and it doesn't include Range. 
https://github.com/jcesarmobile/no-ranges-bug/blob/master/no-ranges-bug/WebViewHandler.swift#L34

Also if the app is inspected in Safari remote inspector, the requests don't show Range in headers neither.
Comment 1 Radar WebKit Bug Importer 2019-10-23 15:32:45 PDT
<rdar://problem/56557566>
Comment 2 Alex Christensen 2019-10-23 17:25:53 PDT
WKURLSchemeHandler is behaving correctly here, and on Mac the same code has a range request.  The problem is on iOS the request we receive from AVAssetResourceLoader does not have a range request, but on Mac the request we receive in the WebCoreNSURLSession has a range request.  I'm uploading a test that verifies this is the case.
Comment 3 Alex Christensen 2019-10-23 17:27:19 PDT
Created attachment 381757 [details]
Patch
Comment 4 Geoffrey Garen 2019-10-23 20:08:45 PDT
Comment on attachment 381757 [details]
Patch

r=me

Can you file a bug report for AVAssetResourceLoader?
Comment 5 jcesarmobile 2019-10-28 11:44:51 PDT
Are you asking me or somebody else?
In case it's me, where should I report the new issue?
Comment 6 Alex Christensen 2019-10-28 14:34:14 PDT
I think he was asking me to report another bug and use this just to commit the test that verifies existing behavior.  I'm still talking to people and deciding what to do about this.
Comment 7 Taehyun Kim 2020-04-22 21:13:52 PDT
We have faced the same no Range header problem using WKURLSchemeHandler for custom video scheme on iOS.

Does it still remain an unresolved bug even after 6 months later from the first report?

Nonetheless, is there any one who happens to know how to detour this bug so that we can manage to catch the Range data from AVAssetResourceLoader?

It is so desperate to finalize our project.
Comment 8 jbgt 2020-09-03 06:10:43 PDT
Hi, any new on this? Is there anywhere we can follow this issue(AVAssetResourceLoader or something else)?
Comment 9 Felix Wansing 2021-03-15 13:46:14 PDT
Hello, is there anything new in this Bug?  The problem persists and makes it impossible to view larger files from local storage.
Comment 10 Alex Christensen 2021-04-30 15:34:36 PDT
Created attachment 427459 [details]
Patch
Comment 11 Geoffrey Garen 2021-04-30 15:48:51 PDT
Comment on attachment 427459 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=427459&action=review

r=me - plz fix test build

> Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:1514
> +            @"Content-Range" : [NSString stringWithFormat:@"bytes %llu-%llu/%lu", rangeBegin, rangeEnd, [videoData length]],
> +            @"Content-Length" : [NSString stringWithFormat:@"%llu", rangeEnd - rangeBegin + 1]

/Volumes/Data/worker/watchOS-7-Build-EWS/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:1513:105: error: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Werror,-Wformat]
Comment 12 Alex Christensen 2021-04-30 15:51:46 PDT
Created attachment 427464 [details]
Patch
Comment 13 Alex Christensen 2021-05-01 18:29:27 PDT
iOS test failures look related.  Will investigate.
Comment 14 Alex Christensen 2021-05-03 12:45:14 PDT
It seems like blob URLs are going through this path too.  I'm going to exclude the blob protocol.
Comment 15 Alex Christensen 2021-05-03 12:46:09 PDT
Created attachment 427587 [details]
Patch
Comment 16 Alex Christensen 2021-05-03 15:53:43 PDT
r276932