Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP/2fy request-upload test around streaming #28236

Merged
merged 2 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions fetch/api/basic/request-upload.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// META: script=/common/get-host-info.sub.js

function testUpload(desc, url, method, createBody, expectedBody) {
const requestInit = {"method": method}
const requestInit = {method};
promise_test(function(test){
const body = createBody();
if (body) {
Expand All @@ -19,7 +19,7 @@ function testUpload(desc, url, method, createBody, expectedBody) {
}

function testUploadFailure(desc, url, method, createBody) {
const requestInit = {"method": method};
const requestInit = {method};
promise_test(t => {
const body = createBody();
if (body) {
Expand Down Expand Up @@ -75,16 +75,7 @@ testUpload("Fetch with POST with Blob body with mime type", url,
"POST",
() => new Blob(["Test"], { type: "text/maybe" }),
"Test");
testUpload("Fetch with POST with ReadableStream", url,
"POST",
() => {
return new ReadableStream({start: controller => {
const encoder = new TextEncoder();
controller.enqueue(encoder.encode("Test"));
controller.close();
}})
},
"Test");

testUploadFailure("Fetch with POST with ReadableStream containing String", url,
"POST",
() => {
Expand Down
39 changes: 39 additions & 0 deletions fetch/api/basic/request-upload.h2.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// META: global=window,worker
// META: script=../resources/utils.js
// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js

function testUpload(desc, url, method, createBody, expectedBody) {
const requestInit = {method};
promise_test(async function(){
const body = createBody();
if (body) {
requestInit["body"] = body;
}
const resp = await fetch(url, requestInit);
const text = await resp.text();
assert_equals(text, expectedBody);
}, desc);
}

const url = RESOURCES_DIR + "echo-content.h2.py"

testUpload("Fetch with POST with empty ReadableStream", url,
"POST",
() => {
return new ReadableStream({start: controller => {
controller.close();
}})
},
"");

testUpload("Fetch with POST with ReadableStream", url,
"POST",
() => {
return new ReadableStream({start: controller => {
const encoder = new TextEncoder();
controller.enqueue(encoder.encode("Test"));
controller.close();
}})
},
"Test");
9 changes: 9 additions & 0 deletions fetch/api/resources/echo-content.h2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from wptserve.utils import isomorphic_encode

def handle_headers(frame, request, response):
response.status = 200
response.headers.update([('Content-Type', 'text/plain')])
response.write_status_headers()

def handle_data(frame, request, response):
response.writer.write_data(frame.data)