Package io.webfolder.cdp.command
Interface Fetch
public interface Fetch
A domain for letting clients substitute browser's network layer with client code.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
continueRequest
(String requestId) Continues the request, optionally modifying some of its parameters.void
continueRequest
(String requestId, String url, String method, String postData, List<HeaderEntry> headers, Boolean interceptResponse) Continues the request, optionally modifying some of its parameters.void
continueResponse
(String requestId) Continues loading of the paused response, optionally modifying the response headers.void
continueResponse
(String requestId, Integer responseCode, String responsePhrase, List<HeaderEntry> responseHeaders, String binaryResponseHeaders) Continues loading of the paused response, optionally modifying the response headers.void
continueWithAuth
(String requestId, AuthChallengeResponse authChallengeResponse) Continues a request supplying authChallengeResponse following authRequired event.void
disable()
Disables the fetch domain.void
enable()
Enables issuing of requestPaused events.void
enable
(List<RequestPattern> patterns, Boolean handleAuthRequests) Enables issuing of requestPaused events.void
failRequest
(String requestId, ErrorReason errorReason) Causes the request to fail with specified reason.void
fulfillRequest
(String requestId, Integer responseCode) Provides response to the request.void
fulfillRequest
(String requestId, Integer responseCode, List<HeaderEntry> responseHeaders, String binaryResponseHeaders, String body, String responsePhrase) Provides response to the request.getResponseBody
(String requestId) Causes the body of the response to be received from the server and returned as a single string.takeResponseBodyAsStream
(String requestId) Returns a handle to the stream representing the response body.
-
Method Details
-
continueRequest
Continues the request, optionally modifying some of its parameters.- Parameters:
requestId
- An id the client received in requestPaused event.
-
continueRequest
void continueRequest(String requestId, String url, String method, String postData, List<HeaderEntry> headers, Boolean interceptResponse) Continues the request, optionally modifying some of its parameters.- Parameters:
requestId
- An id the client received in requestPaused event.url
- If set, the request url will be modified in a way that's not observable by page.method
- If set, the request method is overridden.postData
- If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)headers
- If set, overrides the request headers.interceptResponse
- If set, overrides response interception behavior for this request.
-
continueResponse
Continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.- Parameters:
requestId
- An id the client received in requestPaused event.
-
continueResponse
void continueResponse(String requestId, Integer responseCode, String responsePhrase, List<HeaderEntry> responseHeaders, String binaryResponseHeaders) Continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.- Parameters:
requestId
- An id the client received in requestPaused event.responseCode
- An HTTP response code. If absent, original response code will be used.responsePhrase
- A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.responseHeaders
- Response headers. If absent, original response headers will be used.binaryResponseHeaders
- Alternative way of specifying response headers as a \0-separated series of name: value pairs. Prefer the above method unless you need to represent some non-UTF8 values that can't be transmitted over the protocol as text. (Encoded as a base64 string when passed over JSON)
-
continueWithAuth
Continues a request supplying authChallengeResponse following authRequired event.- Parameters:
requestId
- An id the client received in authRequired event.authChallengeResponse
- Response to with an authChallenge.
-
disable
void disable()Disables the fetch domain. -
enable
void enable()Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth. -
enable
Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.- Parameters:
patterns
- If specified, only requests matching any of these patterns will produce fetchRequested event and will be paused until clients response. If not set, all requests will be affected.handleAuthRequests
- If true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth.
-
failRequest
Causes the request to fail with specified reason.- Parameters:
requestId
- An id the client received in requestPaused event.errorReason
- Causes the request to fail with the given reason.
-
fulfillRequest
Provides response to the request.- Parameters:
requestId
- An id the client received in requestPaused event.responseCode
- An HTTP response code.
-
fulfillRequest
void fulfillRequest(String requestId, Integer responseCode, List<HeaderEntry> responseHeaders, String binaryResponseHeaders, String body, String responsePhrase) Provides response to the request.- Parameters:
requestId
- An id the client received in requestPaused event.responseCode
- An HTTP response code.responseHeaders
- Response headers.binaryResponseHeaders
- Alternative way of specifying response headers as a \0-separated series of name: value pairs. Prefer the above method unless you need to represent some non-UTF8 values that can't be transmitted over the protocol as text. (Encoded as a base64 string when passed over JSON)body
- A response body. If absent, original response body will be used if the request is intercepted at the response stage and empty body will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)responsePhrase
- A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.
-
getResponseBody
Causes the body of the response to be received from the server and returned as a single string. May only be issued for a request that is paused in the Response stage and is mutually exclusive with takeResponseBodyForInterceptionAsStream. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.- Parameters:
requestId
- Identifier for the intercepted request to get body for.- Returns:
- GetResponseBodyResult
-
takeResponseBodyAsStream
Returns a handle to the stream representing the response body. The request must be paused in the HeadersReceived stage. Note that after this command the request can't be continued as is -- client either needs to cancel it or to provide the response body. The stream only supports sequential read, IO.read will fail if the position is specified. This method is mutually exclusive with getResponseBody. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.
-