Skip to content

Commit 522d38b

Browse files
committed
update javadocs
1 parent 32d1e50 commit 522d38b

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

unirest/src/main/java/kong/unirest/core/Config.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,9 @@ public String getDefaultBaseUrl() {
883883
return this.defaultBaseUrl;
884884
}
885885

886+
/**
887+
* @return the custom executor
888+
*/
886889
public Executor getCustomExecutor(){
887890
return customExecutor;
888891
}
@@ -918,6 +921,9 @@ public long getTTL() {
918921
}
919922
}
920923

924+
/**
925+
* @return the RetryStrategy configured
926+
*/
921927
public RetryStrategy getRetryStrategy() {
922928
return retry;
923929
}

unirest/src/main/java/kong/unirest/core/Headers.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import static java.util.stream.Collectors.toList;
3232
import static java.util.stream.Collectors.toSet;
3333

34+
/**
35+
* Represents a collection of headers
36+
*/
3437
public class Headers {
3538

3639
private static final long serialVersionUID = 71310341388734766L;
@@ -147,6 +150,22 @@ public List<Header> all() {
147150
return new ArrayList<>(this.headers);
148151
}
149152

153+
/**
154+
* Add a Cookie header
155+
* @param cookie the cookie
156+
*/
157+
public void cookie(Cookie cookie) {
158+
headers.add(new Entry("cookie", cookie.toString()));
159+
}
160+
161+
/**
162+
* sets a collection of cookies
163+
* @param cookies some cookies
164+
*/
165+
public void cookie(Collection<Cookie> cookies) {
166+
cookies.forEach(this::cookie);
167+
}
168+
150169
private boolean isName(Header h, String name) {
151170
return Util.nullToEmpty(name).equalsIgnoreCase(h.getName());
152171
}
@@ -170,14 +189,6 @@ public String toString() {
170189
return sb.toString();
171190
}
172191

173-
public void cookie(Cookie cookie) {
174-
headers.add(new Entry("cookie", cookie.toString()));
175-
}
176-
177-
public void cookie(Collection<Cookie> cookies) {
178-
cookies.forEach(this::cookie);
179-
}
180-
181192
@Override
182193
public boolean equals(Object o) {
183194
if (this == o) { return true;}
@@ -191,14 +202,30 @@ public int hashCode() {
191202
return Objects.hash(headers);
192203
}
193204

205+
/**
206+
* creates a basic auth header from a username and password.
207+
* The creds will be the Base64 encoded value of {username}:{password} along with the 'Basic' schema
208+
* For example given a creds of "username" and "password" you would get
209+
* eg: Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
210+
* @param username the username
211+
* @param password the password
212+
*/
194213
public void setBasicAuth(String username, String password) {
195214
this.replace("Authorization", Util.toBasicAuthValue(username, password));
196215
}
197216

217+
/**
218+
* sets the Accept header
219+
* @param value the value for accept
220+
*/
198221
public void accepts(String value) {
199222
add(HeaderNames.ACCEPT, value);
200223
}
201224

225+
/**
226+
* Sets headers based on a map of key-value pairs
227+
* @param headerMap I'm the MAP
228+
*/
202229
public void add(Map<String, String> headerMap) {
203230
if (headerMap != null) {
204231
for (Map.Entry<String, String> entry : headerMap.entrySet()) {

unirest/src/main/java/kong/unirest/core/Proxy.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,72 @@
2525

2626
package kong.unirest.core;
2727

28+
/**
29+
* represents basic proxy settings
30+
* When this is used to configure the client it sets the following:
31+
* Proxy host and port are configured as a simple java.net.ProxySelector and set as the default selector
32+
* Username and password are configured as a single java.net.Authenticator which will apply to ALL auth challenges (not just the proxy)
33+
*/
2834
public class Proxy {
2935
private final String host;
3036
private final Integer port;
3137
private final String username;
3238
private final String password;
3339

40+
/**
41+
* Construct just based on host and port
42+
* @param host hostname
43+
* @param port the port
44+
*/
3445
public Proxy(String host, Integer port){
3546
this(host, port, null, null);
3647
}
3748

49+
/**
50+
* Construct with all the things
51+
* @param host hostname
52+
* @param port the port
53+
* @param username username for authentication
54+
* @param password password for authentication
55+
*/
3856
public Proxy(String host, Integer port, String username, String password) {
3957
this.host = host;
4058
this.port = port;
4159
this.username = username;
4260
this.password = password;
4361
}
4462

63+
/**
64+
* @return the host
65+
*/
4566
public String getHost() {
4667
return host;
4768
}
4869

70+
/**
71+
* @return the port
72+
*/
4973
public Integer getPort() {
5074
return port;
5175
}
5276

77+
/**
78+
* @return the username for authentication
79+
*/
5380
public String getUsername() {
5481
return username;
5582
}
5683

84+
/**
85+
* @return the password
86+
*/
5787
public String getPassword() {
5888
return password;
5989
}
6090

91+
/**
92+
* @return indicates that the username and password have been configured.
93+
*/
6194
public boolean isAuthenticated() {
6295
return username != null && password != null;
6396
}

unirest/src/test/java/kong/unirest/core/UtilTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.time.ZonedDateTime;
3333
import java.util.Locale;
3434

35+
import static org.assertj.core.api.Assertions.assertThat;
3536
import static org.junit.jupiter.api.Assertions.assertEquals;
3637

3738
class UtilTest {
@@ -68,4 +69,10 @@ void parseLegacyFormat_whenChinese() {
6869
assertEquals(ZonedDateTime.of(2020,3,6, 16,5,35,0, ZoneId.of("GMT")),
6970
Util.tryParseToDate("Fri, 06 Mar 2020 16:05:35 GMT"));
7071
}
72+
73+
@Test
74+
void basicAuth() {
75+
assertThat(Util.toBasicAuthValue("username", "password"))
76+
.isEqualTo("Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
77+
}
7178
}

0 commit comments

Comments
 (0)