8000 http: Add the "Age" cache header checking · robccan/google-http-java-client@afc6462 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit afc6462

Browse files
committed
http: Add the "Age" cache header checking
https://codereview.appspot.com/7322070/
1 parent dd6e418 commit afc6462

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

google-http-client/src/main/java/com/google/api/client/http/HttpHeaders.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public HttpHeaders() {
168168
@Key("WWW-Authenticate")
169169
private List<String> authenticate;
170170

171+
/** {@code "Age"} header. */
172+
@Key("Age")
173+
private List<Long> age;
174+
171175
@Override
172176
public HttpHeaders clone() {
173177
return (HttpHeaders) super.clone();
@@ -804,6 +808,30 @@ public HttpHeaders setAuthenticate(String authenticate) {
804808
return this;
805809
}
806810

811+
/**
812+
* Returns the first {@code "Age"} header or {@code null} for none.
813+
*
814+
* @since 1.14
815+
*/
816+
public final Long getAge() {
817+
return getFirstHeaderValue(age);
818+
}
819+
820+
/**
821+
* Sets the {@code "Age"} header or {@code null} for none.
822+
*
823+
* <p>
824+
* Overriding is only supported for the purpose of calling the super implementation and changing
825+
* the return type, but nothing else.
826+
* </p>
827+
*
828+
* @since 1.14
829+
*/
830+
public HttpHeaders setAge(Long age) {
831+
this.age = getAsList(age);
832+
return this;
833+
}
834+
807835
/**
808836
* Sets the {@link #authorization} header as specified in <a
809837
* href="http://tools.ietf.org/html/rfc2617#section-2">Basic Authentication Scheme</a>.

google-http-client/src/test/java/com/google/api/client/http/HttpHeadersTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ public static class SlugHeaders extends HttpHeaders {
234234
String slug;
235235
}
236236

237+
public void testParseAge() throws Exception {
238+
MockLowLevelHttpResponse httpResponse = new MockLowLevelHttpResponse()
239+
.setHeaderNames(Arrays.asList("Age"))
240+
.setHeaderValues(Arrays.asList("3456"));
241+
242+
HttpHeaders httpHeaders = new HttpHeaders();
243+
httpHeaders.fromHttpResponse(httpResponse, null);
244+
assertEquals(3456L, httpHeaders.getAge().longValue());
245+
}
246+
237247
public void testFromHttpResponse_normalFlow() throws Exception {
238248
MockLowLevelHttpResponse httpResponse = new MockLowLevelHttpResponse().setHeaderNames(
239249
Arrays.asList("Content-Type", "Slug"))

0 commit comments

Comments
 (0)
0