Created
June 4, 2016 06:42
-
-
Save slawekradzyminski/4f03f37d36b033f45d80f921206786f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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