Custom ResourceHandler problem with Range requests

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Custom ResourceHandler problem with Range requests

Postby swnghty » Thu Jan 09, 2020 3:58 am

CEF Version: 78.3.1+g8819d2e+chromium-78.0.3904.87

Hi, everyone!

I have a problem with using of custom ResourceHandler when Range request occured.

1. HTTP request for large file downloading is formed on web side with header:

Code: Select all
Range: bytes=0-


2. My implementation of ResourceHandler make this request and returns response with header:

Code: Select all
Content-Range: 0-8716288/8769105


3. Second HTTP request for continuing file downloading is formed on web side with header:

Code: Select all
Range: bytes=8716288-


4. CEF code process this header and fill byte_range_ : net::HttpByteRange in StreamReaderURLLoader with 8716288 as first_byte_position_ and -1 as last_byte_position_

5. CEF code calls Skip() method of my ResourceHandler implementation with bytes_to_skip == 8716288:

Code: Select all
bool MyResourceHandler::Skip(int64 bytes_to_skip,
    int64& bytes_skipped,
    CefRefPtr<CefResourceSkipCallback> callback)
{
    bytes_skipped = bytes_to_skip;
    return true;
}

I set bytes_skipped equal bytes_to_skip.

6. Then DCHECK_GE alerts in this code:

Code: Select all
//  cef\libcef\browser\net_service\stream_reader_url_loader.cc
void StreamReaderURLLoader::OnReaderSkipCompleted(int64_t bytes_skipped) {
  DCHECK(thread_checker_.CalledOnValidThread());

  if (!byte_range_valid()) {
    // Expected content length is unspecified.
    HeadersComplete(net::HTTP_OK, -1);
  } else if (bytes_skipped == byte_range_.first_byte_position()) {
    // We skipped the expected number of bytes.
    int64_t expected_content_length = byte_range_.last_byte_position() -
                                      byte_range_.first_byte_position() + 1;
    DCHECK_GE(expected_content_length, 0);
    HeadersComplete(net::HTTP_OK, expected_content_length);
  } else {
    RequestComplete(bytes_skipped < 0 ? bytes_skipped : net::ERR_FAILED);
  }
}

Because:
expected_content_length == -1 - 8716288 + 1 == -8716288 <-- not greater or equal zero :(


And this is my question:
Is it a bug in CEF code or what do I doing wrong?
swnghty
Newbie
 
Posts: 1
Joined: Thu Jan 09, 2020 3:52 am

Re: Custom ResourceHandler problem with Range requests

Postby magreenblatt » Thu Jan 09, 2020 6:55 am

Seems like a grey area to me. The current code expects to calculate the content length, but your example doesn't provide enough information (e.g. |last_byte_position_| is -1). The CEF code could probably be fixed to deal with this case, along with any related issues in downstream code. A PR to do so would be welcome.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Custom ResourceHandler problem with Range requests

Postby magreenblatt » Thu Jan 09, 2020 6:58 am

I've linked this thread from https://bitbucket.org/chromiumembedded/cef/issues/1742, which is related.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 34 guests