mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add ning http headers class
This commit is contained in:
parent
34e558ab63
commit
6c71c2cb97
2 changed files with 61 additions and 2 deletions
|
@ -0,0 +1,46 @@
|
|||
package uk.ac.ic.wlgitbridge.io.http.ning;
|
||||
|
||||
import com.ning.http.client.FluentCaseInsensitiveStringsMap;
|
||||
import com.ning.http.client.HttpResponseHeaders;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class NingHttpHeaders extends HttpResponseHeaders {
|
||||
|
||||
private final FluentCaseInsensitiveStringsMap map;
|
||||
|
||||
private NingHttpHeaders(FluentCaseInsensitiveStringsMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public static NingHttpHeadersBuilder builder() {
|
||||
return new NingHttpHeadersBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluentCaseInsensitiveStringsMap getHeaders() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static class NingHttpHeadersBuilder {
|
||||
|
||||
private final Map<String, Collection<String>> map;
|
||||
|
||||
private NingHttpHeadersBuilder() {
|
||||
map = new HashMap<>();
|
||||
}
|
||||
|
||||
public NingHttpHeadersBuilder addHeader(String key, String... values) {
|
||||
map.computeIfAbsent(key, __ -> new ArrayList<>())
|
||||
.addAll(Arrays.asList(values));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NingHttpHeaders build() {
|
||||
return new NingHttpHeaders(
|
||||
new FluentCaseInsensitiveStringsMap(map));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,19 @@
|
|||
package uk.ac.ic.wlgitbridge.bridge.resource;
|
||||
|
||||
import com.ning.http.client.HttpResponseHeaders;
|
||||
import org.junit.Test;
|
||||
import uk.ac.ic.wlgitbridge.bridge.db.noop.NoopDbStore;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
|
||||
import uk.ac.ic.wlgitbridge.io.http.ning.NingHttpClientFacade;
|
||||
import uk.ac.ic.wlgitbridge.io.http.ning.NingHttpHeaders;
|
||||
import uk.ac.ic.wlgitbridge.util.FunctionT;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UrlResourceCacheTest {
|
||||
|
||||
|
@ -22,6 +28,13 @@ public class UrlResourceCacheTest {
|
|||
private final UrlResourceCache cache
|
||||
= new UrlResourceCache(new NoopDbStore(), http);
|
||||
|
||||
private static HttpResponseHeaders withContentLength(long cl) {
|
||||
return NingHttpHeaders
|
||||
.builder()
|
||||
.addHeader("Content-Length", String.valueOf(cl))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getThrowsSizeLimitWhenContentLengthTooBig() throws Exception {
|
||||
when(http.get(any(), any())).thenAnswer(invoc -> {
|
||||
|
@ -35,7 +48,7 @@ public class UrlResourceCacheTest {
|
|||
|
||||
cache.get(
|
||||
PROJ, URL, NEW_PATH,
|
||||
Collections.emptyMap(), Collections.emptyMap(),
|
||||
new HashMap<>(), new HashMap<>(),
|
||||
Optional.of(2L)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue