fix: passing content-length down the stream for intercepted requests (#25324)

* fix: pass content length if avilable in headers

* fix: fixed unit test after changes

	video is being played for standard scheme when
	content-length is available

* fix: fixed review remakrs

added is_string check and changed stol to StringToInt64

* fix: fix test case name

* fix: fixed typo
This commit is contained in:
marcin-prochownik 2020-10-06 02:53:13 +02:00 committed by GitHub
parent 6356cd4018
commit fec1c0b68b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -9,6 +9,7 @@
#include <utility>
#include "base/guid.h"
#include "base/strings/string_number_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/binding.h"
@ -123,11 +124,16 @@ network::mojom::URLResponseHeadPtr ToResponseHead(
} else {
continue;
}
// Some apps are passing content-type via headers, which is not accepted
// in NetworkService.
if (base::ToLowerASCII(iter.first) == "content-type") {
auto header_name_lowercase = base::ToLowerASCII(iter.first);
if (header_name_lowercase == "content-type") {
// Some apps are passing content-type via headers, which is not accepted
// in NetworkService.
head->headers->GetMimeTypeAndCharset(&head->mime_type, &head->charset);
has_content_type = true;
} else if (header_name_lowercase == "content-length" &&
iter.second.is_string()) {
base::StringToInt64(iter.second.GetString(), &head->content_length);
}
}
}

View file

@ -919,11 +919,11 @@ describe('protocol module', () => {
await protocol.unregisterProtocol('stream');
});
it('does not successfully play videos with stream: false on streaming protocols', async () => {
await streamsResponses(standardScheme, 'error');
it('successfully plays videos when content is buffered (stream: false)', async () => {
await streamsResponses(standardScheme, 'play');
});
it('successfully plays videos with stream: true on streaming protocols', async () => {
it('successfully plays videos when streaming content (stream: true)', async () => {
await streamsResponses('stream', 'play');
});