-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect the 206 paged response from the server group logs endpoint.
Prevent the deduplicate message logic firing and log it if it does.
- Loading branch information
1 parent
07b0d8c
commit 054c705
Showing
6 changed files
with
206 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...al/service/src/main/java/org/whispersystems/signalservice/internal/push/ContentRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.whispersystems.signalservice.internal.push; | ||
|
||
import org.whispersystems.libsignal.util.guava.Optional; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public final class ContentRange { | ||
private static final Pattern PATTERN = Pattern.compile("versions (\\d+)-(\\d+)\\/(\\d+)"); | ||
|
||
private final int rangeStart; | ||
private final int rangeEnd; | ||
private final int totalSize; | ||
|
||
/** | ||
* Parses a content range header. | ||
*/ | ||
public static Optional<ContentRange> parse(String header) { | ||
if (header != null) { | ||
Matcher matcher = PATTERN.matcher(header); | ||
|
||
if (matcher.matches()) { | ||
return Optional.of(new ContentRange(Integer.parseInt(matcher.group(1)), | ||
Integer.parseInt(matcher.group(2)), | ||
Integer.parseInt(matcher.group(3)))); | ||
} | ||
} | ||
|
||
return Optional.absent(); | ||
} | ||
|
||
private ContentRange(int rangeStart, int rangeEnd, int totalSize) { | ||
this.rangeStart = rangeStart; | ||
this.rangeEnd = rangeEnd; | ||
this.totalSize = totalSize; | ||
} | ||
|
||
public int getRangeStart() { | ||
return rangeStart; | ||
} | ||
|
||
public int getRangeEnd() { | ||
return rangeEnd; | ||
} | ||
|
||
public int getTotalSize() { | ||
return totalSize; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...src/test/java/org/whispersystems/signalservice/internal/push/ContentRange_parse_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.whispersystems.signalservice.internal.push; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(Parameterized.class) | ||
public final class ContentRange_parse_Test { | ||
|
||
@Parameterized.Parameter(0) | ||
public String input; | ||
|
||
@Parameterized.Parameter(1) | ||
public int expectedRangeStart; | ||
|
||
@Parameterized.Parameter(2) | ||
public int expectedRangeEnd; | ||
|
||
@Parameterized.Parameter(3) | ||
public int expectedSize; | ||
|
||
@Parameterized.Parameters(name = "Content-Range: \"{0}\"") | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][]{ | ||
{ "versions 1-2/3", 1, 2, 3 }, | ||
{ "versions 23-45/67", 23, 45, 67 }, | ||
}); | ||
} | ||
|
||
@Test | ||
public void rangeStart() { | ||
assertEquals(expectedRangeStart, ContentRange.parse(input).get().getRangeStart()); | ||
} | ||
|
||
@Test | ||
public void rangeEnd() { | ||
assertEquals(expectedRangeEnd, ContentRange.parse(input).get().getRangeEnd()); | ||
} | ||
|
||
@Test | ||
public void totalSize() { | ||
assertEquals(expectedSize, ContentRange.parse(input).get().getTotalSize()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...hispersystems/signalservice/internal/push/ContentRange_parse_withInvalidStrings_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.whispersystems.signalservice.internal.push; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
@RunWith(Parameterized.class) | ||
public final class ContentRange_parse_withInvalidStrings_Test { | ||
|
||
@Parameterized.Parameter(0) | ||
public String input; | ||
|
||
@Parameterized.Parameters(name = "Content-Range: \"{0}\"") | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][]{ | ||
{ null }, | ||
{ "" }, | ||
{ "23-45/67" }, | ||
{ "ersions 23-45/67" }, | ||
{ "versions 23-45" }, | ||
{ "versions a-b/c" } | ||
}); | ||
} | ||
|
||
@Test | ||
public void parse_should_be_absent() { | ||
assertFalse(ContentRange.parse(input).isPresent()); | ||
} | ||
} |