Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Commit 430cd55

Browse files
fix: name of properties
1 parent 9da5db5 commit 430cd55

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Your client can be used with [brightData](brightdata.com) proxy.
1919
If you want to use this proxy, you have to configure it.
2020

2121
```java
22-
System.setProperty("httpClientWrapperBrightDataHost", "YOUR_HOST");
23-
System.setProperty("httpClientWrapperBrightDataPort", "YOUR_PORT");
24-
System.setProperty("httpClientWrapperBrightDataUsername", "YOUR_USERNAME");
25-
System.setProperty("httpClientWrapperBrightDataPassword", "YOUR_PASSWORD");
22+
System.setProperty("httpclient.wrapper.proxy.bright-data.host", "YOUR_HOST");
23+
System.setProperty("httpclient.wrapper.proxy.bright-data.port", "YOUR_PORT");
24+
System.setProperty("httpclient.wrapper.proxy.bright-data.username", "YOUR_USERNAME");
25+
System.setProperty("httpclient.wrapper.proxy.bright-data.password", "YOUR_PASSWORD");
2626
```

src/main/java/net/httpclient/wrapper/HttpClientWrapper.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class HttpClientWrapper {
1515
*/
1616
public static boolean hasValidBrightDataProperty() {
1717
String[] properties = new String[] {
18-
"httpClientWrapperBrightDataHost",
19-
"httpClientWrapperBrightDataPort",
20-
"httpClientWrapperBrightDataUsername",
21-
"httpClientWrapperBrightDataPassword"
18+
"httpclient.wrapper.proxy.bright-data.host",
19+
"httpclient.wrapper.proxy.bright-data.port",
20+
"httpclient.wrapper.proxy.bright-data.username",
21+
"httpclient.wrapper.proxy.bright-data.password"
2222
};
2323
for (String property : properties) {
2424
if (System.getProperty(property) == null) {
@@ -33,31 +33,31 @@ public static boolean hasValidBrightDataProperty() {
3333
* @return The brightdata host property set.
3434
*/
3535
public static String getBrightDataHost() {
36-
return (System.getProperty("httpClientWrapperBrightDataHost"));
36+
return (System.getProperty("httpclient.wrapper.proxy.bright-data.host"));
3737
}
3838

3939
/**
4040
* This function will return the brightdata port property set.
4141
* @return The brightdata port property set.
4242
*/
4343
public static int getBrightDataPort() {
44-
return (Integer.parseInt(System.getProperty("httpClientWrapperBrightDataPort")));
44+
return (Integer.parseInt(System.getProperty("httpclient.wrapper.proxy.bright-data.port")));
4545
}
4646

4747
/**
4848
* This function will return the brightdata username property set.
4949
* @return The brightdata username property set.
5050
*/
5151
public static String getBrightDataUsername() {
52-
return (System.getProperty("httpClientWrapperBrightDataUsername"));
52+
return (System.getProperty("httpclient.wrapper.proxy.bright-data.username"));
5353
}
5454

5555
/**
5656
* This function will return the brightdata password property set.
5757
* @return The brightdata password property set.
5858
*/
5959
public static String getBrightDataPassword() {
60-
return (System.getProperty("httpClientWrapperBrightDataPassword"));
60+
return (System.getProperty("httpclient.wrapper.proxy.bright-data.password"));
6161
}
6262

6363
}

src/main/java/net/httpclient/wrapper/session/HttpClientSession.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.http.impl.client.LaxRedirectStrategy;
3030
import org.apache.http.ssl.SSLContextBuilder;
3131
import org.jetbrains.annotations.NotNull;
32+
import org.jetbrains.annotations.Nullable;
3233
import org.json.JSONObject;
3334

3435
import javax.net.ssl.SSLContext;
@@ -162,13 +163,38 @@ public HttpClient newHttpClient() throws NoSuchAlgorithmException, KeyManagement
162163
*/
163164

164165
public RequestResponse sendPost(String url, String content, ContentType contentType) throws IOException, HttpClientException, HttpServerException {
166+
return (sendPost(url, content, contentType, null));
167+
}
168+
169+
public RequestResponse sendPost(@NotNull String url,
170+
@NotNull JSONObject content,
171+
@NotNull ContentType contentType) throws HttpClientException, IOException, HttpServerException {
172+
return (sendPost(url, content.toString(), contentType, null));
173+
}
174+
175+
public RequestResponse sendPost(@NotNull String url,
176+
@NotNull JSONObject content,
177+
@NotNull ContentType contentType,
178+
@Nullable List<Header> headers) throws HttpClientException, IOException, HttpServerException {
179+
return (sendPost(url, content.toString(), contentType, headers));
180+
}
181+
182+
public RequestResponse sendPost(@NotNull String url,
183+
@NotNull String content,
184+
@NotNull ContentType contentType,
185+
@Nullable List<Header> headers) throws IOException,
186+
HttpClientException, HttpServerException {
165187
Date start = new Date();
166188
String oldCookieStoreSerialized = BasicCookieStoreSerializerUtils.serializableToBase64(httpCookieStore);
167189

168190
HttpPost httpPost = new HttpPost(url);
169191
httpPost.setConfig(getRequestConfig().build());
170192
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, contentType.getMimeType());
171193
httpPost.addHeader(HttpHeaders.ACCEPT, "application/json, text/plain, */*");
194+
if (headers != null) {
195+
for (Header header : headers)
196+
httpPost.addHeader(header);
197+
}
172198
httpPost.setEntity(new StringEntity(content));
173199
HttpResponse httpResponse = getHttpClient().execute(httpPost);
174200

src/test/java/net/httpclient/wrapper/ratelimiter/RateLimiterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void acquireTest() {
2929
}
3030

3131
@Test
32-
public void getRemainingTimeTest() throws InterruptedException {
32+
public void getRemainingTimeTest() {
3333
int durationInSeconds = 3;
3434
RateLimiter rateLimiter = new RateLimiter(Duration.ofSeconds(durationInSeconds));
3535
rateLimiter.acquire();

0 commit comments

Comments
 (0)