Skip to content

Commit e555ed4

Browse files
committed
Added default query
1 parent 46cdee7 commit e555ed4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/java/org/javawebstack/httpclient/HTTPClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class HTTPClient {
1717
private int timeout = 5000;
1818
private String baseUrl = "";
1919
private Map<String, String> defaultHeaders = new HashMap<>();
20+
private Map<String, String> defaultQuery = new HashMap<>();
2021

2122
public HTTPClient gson(Gson gson){
2223
this.gson = gson;
@@ -41,10 +42,24 @@ public HTTPClient header(String key, String value){
4142
return this;
4243
}
4344

45+
public HTTPClient query(String key, String value){
46+
defaultQuery.put(key, value);
47+
return this;
48+
}
49+
50+
public Map<String, String> getDefaultQuery() {
51+
return defaultQuery;
52+
}
53+
4454
public Map<String, String> getDefaultHeaders() {
4555
return defaultHeaders;
4656
}
4757

58+
public HTTPClient setDefaultQuery(Map<String, String> defaultQuery) {
59+
this.defaultQuery = defaultQuery;
60+
return this;
61+
}
62+
4863
public HTTPClient headers(Map<String, String> defaultHeaders){
4964
this.defaultHeaders = defaultHeaders;
5065
return this;

src/main/java/org/javawebstack/httpclient/HTTPRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public HTTPRequest(HTTPClient client, String method, String path){
2929
this.client = client;
3030
this.method = method;
3131
this.path = path;
32+
for(String key : client.getDefaultQuery().keySet())
33+
query(key, client.getDefaultQuery().get(key));
34+
for(String key : client.getDefaultHeaders().keySet())
35+
header(key, client.getDefaultHeaders().get(key));
3236
}
3337

3438
public HTTPRequest header(String key, String value){

0 commit comments

Comments
 (0)