fix: do not modify fetch options.method (#1232)
This commit is contained in:
@@ -193,7 +193,7 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
|
||||
private static RequestOptionsImpl ensureOptions(RequestOptions options, String method) {
|
||||
RequestOptionsImpl impl = (RequestOptionsImpl) options;
|
||||
RequestOptionsImpl impl = Utils.clone((RequestOptionsImpl) options);
|
||||
if (impl == null) {
|
||||
impl = new RequestOptionsImpl();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.ElementHandle;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.HttpHeader;
|
||||
@@ -80,6 +81,14 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
static <T> T clone(T f) {
|
||||
if (f == null) {
|
||||
return f;
|
||||
}
|
||||
return convertType(f, (Class<T>) f.getClass());
|
||||
}
|
||||
|
||||
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('/', '$', '^', '+', '.', '(', ')', '=', '!', '|'));
|
||||
|
||||
static String globToRegex(String glob) {
|
||||
|
||||
@@ -380,4 +380,35 @@ public class TestGlobalFetch extends TestBase {
|
||||
}
|
||||
request.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotModifyRequestMethodInOptions() {
|
||||
APIRequestContext request = playwright.request().newContext();
|
||||
server.setRoute("/empty.html", exchange -> {
|
||||
exchange.getResponseHeaders().set("Content-type", "text/plain");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write(exchange.getRequestMethod());
|
||||
}
|
||||
});
|
||||
RequestOptions options = RequestOptions.create();
|
||||
options.setTimeout(10000);
|
||||
{
|
||||
APIResponse response = request.fetch(server.EMPTY_PAGE, options);
|
||||
assertTrue(response.ok());
|
||||
assertEquals("GET", response.text());
|
||||
}
|
||||
{
|
||||
APIResponse response = request.delete(server.EMPTY_PAGE, options);
|
||||
assertTrue(response.ok());
|
||||
assertEquals("DELETE", response.text());
|
||||
}
|
||||
{
|
||||
APIResponse response = request.put(server.EMPTY_PAGE, options);
|
||||
assertTrue(response.ok());
|
||||
assertEquals("PUT", response.text());
|
||||
}
|
||||
request.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user