-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,14 @@ | |
|
||
import org.openqa.selenium.remote.http.AddSeleniumUserAgent; | ||
import org.openqa.selenium.remote.http.ClientConfig; | ||
import org.openqa.selenium.remote.http.Contents; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
import org.openqa.selenium.remote.http.HttpRequest; | ||
import org.openqa.selenium.remote.http.HttpResponse; | ||
|
||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.net.URLEncoder; | ||
import java.net.http.HttpRequest.BodyPublishers; | ||
import java.util.Objects; | ||
|
@@ -68,18 +71,24 @@ public java.net.http.HttpRequest createRequest(HttpRequest req) { | |
break; | ||
|
||
case POST: | ||
builder = builder.POST(BodyPublishers.ofInputStream(req.getContent())); | ||
break; | ||
// Copy the content into a byte array to avoid reading the content inputstream multiple times. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pujagani
Author
Contributor
|
||
builder = builder.POST(BodyPublishers.ofByteArray(Contents.bytes(req.getContent()))); | ||
break; | ||
|
||
case PUT: | ||
builder = builder.PUT(BodyPublishers.ofInputStream(req.getContent())); | ||
builder = builder.PUT(BodyPublishers.ofByteArray(Contents.bytes(req.getContent()))); | ||
break; | ||
|
||
default: | ||
throw new IllegalArgumentException(String.format("Unsupported request method %s: %s", req.getMethod(), req)); | ||
} | ||
|
||
for (String name : req.getHeaderNames()) { | ||
// Avoid explicitly setting content-length | ||
// This prevents the IllegalArgumentException that states 'restricted header name: "Content-Length"' | ||
if (name.equals("Content-Length")) { | ||
This comment has been minimized.
Sorry, something went wrong.
joerg1985
Member
|
||
continue; | ||
} | ||
for (String value : req.getHeaders(name)) { | ||
builder = builder.header(name, value); | ||
} | ||
|
@@ -106,6 +115,11 @@ private String getRawUrl(URI baseUrl, String uri) { | |
return rawUrl; | ||
} | ||
|
||
public URI getRawURI(HttpRequest req) { | ||
String rawUrl = getRawUrl(config.baseUri(), req.getUri()); | ||
return URI.create(rawUrl); | ||
} | ||
|
||
public HttpResponse createResponse(java.net.http.HttpResponse<InputStream> response) { | ||
HttpResponse res = new HttpResponse(); | ||
res.setStatus(response.statusCode()); | ||
|
isn't this the body of the request? i think this should not be red multiple times by the java implementation.
the response body handler is defined in JdkHttpClient#execute