Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/io/vertx/httpproxy/impl/CacheControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CacheControl {
public CacheControl parse(String header) {
maxAge = -1;
_public = false;
String[] parts = header.split(","); // No regex
String[] parts = header.split(",\\s*|\\s+");
for (String part : parts) {
part = part.trim().toLowerCase();
switch (part) {
Expand All @@ -31,7 +31,6 @@ public CacheControl parse(String header) {
default:
if (part.startsWith("max-age=")) {
maxAge = Integer.parseInt(part.substring(8));

}
break;
}
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/io/vertx/tests/parsing/ParseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@ public void testParseCacheControlPublic() {
Assert.assertTrue(control.parse("public").isPublic());
}


@Test
public void testCommaSplit(){
CacheControl control = new CacheControl();
Assert.assertTrue(control.parse("max-age=123,public,no-cache").isPublic());
Assert.assertEquals(control.parse("max-age=123,public,no-cache").maxAge(), 123);
Assert.assertEquals(control.parse("max-age=12121212").maxAge(), 12121212);
}

@Test
public void testSpaceSplit(){
CacheControl control = new CacheControl();
Assert.assertTrue(control.parse("max-age=123 public no-cache").isPublic());
Assert.assertEquals(control.parse("max-age=123 public no-cache").maxAge(), 123);
Assert.assertEquals(control.parse("max-age=12121212").maxAge(), 12121212);
}

@Test
public void testCommaAndSpaceSplit(){
CacheControl control = new CacheControl();
Assert.assertTrue(control.parse("max-age=123, public, no-cache").isPublic());
Assert.assertEquals(control.parse("max-age=123, public, no-cache").maxAge(), 123);
Assert.assertEquals(control.parse("max-age=12121212").maxAge(), 12121212);
}

@Test
public void testCaseInsensitiveParsing() {
CacheControl control = new CacheControl();
CacheControl parsed = control.parse("MaX-AgE=999, PuBLic");
Assert.assertTrue(parsed.isPublic());
Assert.assertEquals(999, parsed.maxAge());
}

@Test
public void testExtraSpacesAndCommas() {
CacheControl control = new CacheControl();
CacheControl parsed = control.parse(" , max-age=45 , , public ");
Assert.assertTrue(parsed.isPublic());
Assert.assertEquals(45, parsed.maxAge());
}


/*
@Test
public void testCommaSplit() {
Expand Down