Skip to content

Commit

Permalink
create TankConfig once
Browse files Browse the repository at this point in the history
  • Loading branch information
zkofiro committed Sep 18, 2024
1 parent c214535 commit 74d1954
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ public class TankHttpClient3 implements TankHttpClient {

private HttpClient httpclient;

private TankConfig tankConfig;

/**
* no-arg constructor for client
*/
public TankHttpClient3() {
tankConfig = new TankConfig();
httpclient = new HttpClient();
httpclient.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY);
httpclient.getParams().setBooleanParameter("http.protocol.single-cookie-header", true);
Expand Down Expand Up @@ -309,7 +312,7 @@ private String getContentHeader(HttpMethod method) {
* @param contentType
*/
private boolean checkContentType(String contentType) {
Collection<String> mimeTypes = new TankConfig().getAgentConfig().getTextMimeTypeRegex();
Collection<String> mimeTypes = tankConfig.getAgentConfig().getTextMimeTypeRegex();
for (String regex : mimeTypes) {
if (contentType.matches(regex)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ public class TankHttpClient4 implements TankHttpClient {

private CloseableHttpClient httpclient;
private HttpClientContext context;
private TankConfig tankConfig;

/**
* no-arg constructor for client
*/
public TankHttpClient4() {
tankConfig = new TankConfig();
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(30000)
Expand Down Expand Up @@ -338,7 +340,7 @@ private void sendRequest(BaseRequest request, @Nonnull HttpRequestBase method, S
* @param contentType
*/
private boolean checkContentType(String contentType) {
Collection<String> mimeTypes = new TankConfig().getAgentConfig().getTextMimeTypeRegex();
Collection<String> mimeTypes = tankConfig.getAgentConfig().getTextMimeTypeRegex();
for (String regex : mimeTypes) {
if (contentType.matches(regex)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ public class TankHttpClientJDK implements TankHttpClient {
private HttpClient httpclient;
private HttpClient.Builder httpclientBuilder;
private final CookieManager cookieManager = new CookieManager();
private TankConfig tankConfig;

/**
* no-arg constructor for client
*/
public TankHttpClientJDK() {
tankConfig = new TankConfig();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
httpclientBuilder = HttpClient.newBuilder()
.cookieHandler(cookieManager)
Expand Down Expand Up @@ -256,7 +258,7 @@ private void sendRequest(BaseRequest request, @Nonnull HttpRequest method, Strin
* @param contentType
*/
private boolean checkContentType(String contentType) {
Collection<String> mimeTypes = new TankConfig().getAgentConfig().getTextMimeTypeRegex();
Collection<String> mimeTypes = tankConfig.getAgentConfig().getTextMimeTypeRegex();
for (String regex : mimeTypes) {
if (contentType.matches(regex)) {
return true;
Expand Down

0 comments on commit 74d1954

Please sign in to comment.