Skip to content

Instantly share code, notes, and snippets.

@slawekradzyminski
Created June 4, 2016 06:42
Show Gist options
  • Save slawekradzyminski/4f03f37d36b033f45d80f921206786f0 to your computer and use it in GitHub Desktop.
Save slawekradzyminski/4f03f37d36b033f45d80f921206786f0 to your computer and use it in GitHub Desktop.
class Request {
private URI linkToCheck;
private WebDriver driver;
Request() {
}
void setURIToCheck(String linkToCheck) throws URISyntaxException {
this.linkToCheck = new URI(linkToCheck);
}
int getHTTPStatusCodeFromResponse() throws IOException {
return getHttpResponse().getStatusLine().getStatusCode();
}
private HttpResponse getHttpResponse() throws IOException {
HttpClient client = initializeHttpClient();
BasicHttpContext httpContext = new BasicHttpContext();
if (driver != null) {
addCookies(httpContext);
}
HttpRequestBase request = buildRequest();
return client.execute(request, httpContext);
}
private HttpClient initializeHttpClient() {
return HttpClientBuilder
.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
}
private HttpRequestBase buildRequest() {
HttpRequestBase requestMethod = new HttpGet();
requestMethod.setURI(this.linkToCheck);
return requestMethod;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment