mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-12-28 18:30:43 +00:00
fix: change postData field type to Object (#296)
This commit is contained in:
parent
aa853e8386
commit
80c11f76aa
@ -37,7 +37,7 @@ public interface Route {
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
*/
|
||||
public byte[] postData;
|
||||
public Object postData;
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
@ -52,7 +52,7 @@ public interface Route {
|
||||
return this;
|
||||
}
|
||||
public ResumeOptions withPostData(String postData) {
|
||||
this.postData = postData.getBytes(StandardCharsets.UTF_8);
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
public ResumeOptions withPostData(byte[] postData) {
|
||||
|
||||
@ -22,6 +22,7 @@ import com.microsoft.playwright.Request;
|
||||
import com.microsoft.playwright.Route;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -61,7 +62,15 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
params.add("headers", Serialization.toProtocol(options.headers));
|
||||
}
|
||||
if (options.postData != null) {
|
||||
String base64 = Base64.getEncoder().encodeToString(options.postData);
|
||||
byte[] bytes = null;
|
||||
if (options.postData instanceof byte[]) {
|
||||
bytes = (byte[]) options.postData;
|
||||
} else if (options.postData instanceof String) {
|
||||
bytes = ((String) options.postData).getBytes(StandardCharsets.UTF_8);
|
||||
} else {
|
||||
throw new PlaywrightException("postData must be either String or byte[], found: " + options.postData.getClass().getName());
|
||||
}
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
params.addProperty("postData", base64);
|
||||
}
|
||||
sendMessage("continue", params);
|
||||
|
||||
@ -289,6 +289,9 @@ class TypeRef extends Element {
|
||||
|
||||
private JsonObject stripNullable() {
|
||||
JsonObject jsonType = jsonElement.getAsJsonObject();
|
||||
if (!isNullable()) {
|
||||
return jsonType;
|
||||
}
|
||||
if (!jsonType.has("union")) {
|
||||
return jsonType;
|
||||
}
|
||||
@ -696,12 +699,6 @@ class Field extends Element {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("Route.resume.options.postData".equals(jsonPath)) {
|
||||
output.add(offset + "public " + parentClass + " withPostData(String postData) {");
|
||||
output.add(offset + " this.postData = postData.getBytes(StandardCharsets.UTF_8);");
|
||||
output.add(offset + " return this;");
|
||||
output.add(offset + "}");
|
||||
}
|
||||
writeGenericBuilderMethod(output, offset, parentClass, type.toJava());
|
||||
}
|
||||
|
||||
|
||||
@ -50,9 +50,6 @@ class Types {
|
||||
add("BrowserContext.exposeFunction.callback", "function", "FunctionCallback");
|
||||
add("Page.exposeBinding.callback", "function", "BindingCallback");
|
||||
add("Page.exposeFunction.callback", "function", "FunctionCallback");
|
||||
|
||||
// The method has custom signatures
|
||||
add("Route.resume.options.postData", "Buffer|string", "byte[]", new Empty());
|
||||
}
|
||||
|
||||
Mapping findForPath(String jsonPath) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user