MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / getResponse

Method getResponse

src/test/java/org/htmlunit/doc/DetailsTest.java:65–83  ·  view source on GitHub ↗
(final WebRequest request)

Source from the content-addressed store, hash-verified

63 new WebConnectionWrapper(webClient) {
64
65 @Override
66 public WebResponse getResponse(final WebRequest request) throws IOException {
67 final URL requestUrl = request.getUrl();
68 // check the request url
69 // if is allowed simple call super.
70
71 if (!isBlocked(requestUrl)) {
72 return super.getResponse(request);
73 }
74
75 // construct alternative response
76 final String content = "<html><html>";
77 final WebResponseData data = new WebResponseData(content.getBytes(StandardCharsets.UTF_8),
78 HttpStatus.OK_200, "blocked", Collections.emptyList());
79 final WebResponse blocked = new WebResponse(data, request, 0L);
80 // if you like to check later on for blocked responses
81 blocked.markAsBlocked("Blocked URL: '" + requestUrl.toExternalForm() + "'");
82 return blocked;
83 }
84
85 private boolean isBlocked(final URL requestUrl) {
86 return true;

Callers

nothing calls this directly

Calls 5

isBlockedMethod · 0.95
markAsBlockedMethod · 0.95
getUrlMethod · 0.65
getResponseMethod · 0.65
getBytesMethod · 0.65

Tested by

no test coverage detected