use of com.artipie.http.Headers in project artipie by artipie.
the class DockerProxyTest method shouldFailBuildFromBadConfig.
@ParameterizedTest
@MethodSource("badConfigs")
void shouldFailBuildFromBadConfig(final String yaml) throws Exception {
final Slice slice = dockerProxy(yaml);
Assertions.assertThrows(RuntimeException.class, () -> slice.response(new RequestLine(RqMethod.GET, "/").toString(), Headers.EMPTY, Flowable.empty()).send((status, headers, body) -> CompletableFuture.allOf()).toCompletableFuture().join());
}
use of com.artipie.http.Headers in project maven-adapter by artipie.
the class CachedProxySlice method response.
@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final RequestLineFrom req = new RequestLineFrom(line);
final Key key = new KeyFromPath(req.uri().getPath());
return new AsyncResponse(new RepoHead(this.client).head(req.uri().getPath()).thenCompose(head -> this.cache.load(key, new Remote.WithErrorHandling(() -> {
final CompletableFuture<Optional<? extends Content>> promise = new CompletableFuture<>();
this.client.response(line, Headers.EMPTY, Content.EMPTY).send((rsstatus, rsheaders, rsbody) -> {
final CompletableFuture<Void> term = new CompletableFuture<>();
if (rsstatus.success()) {
final Flowable<ByteBuffer> res = Flowable.fromPublisher(rsbody).doOnError(term::completeExceptionally).doOnTerminate(() -> term.complete(null));
promise.complete(Optional.of(new Content.From(res)));
} else {
promise.complete(Optional.empty());
}
return term;
});
return promise;
}), new CacheControl.All(StreamSupport.stream(head.orElse(Headers.EMPTY).spliterator(), false).map(Header::new).map(CachedProxySlice::checksumControl).collect(Collectors.toUnmodifiableList()))).handle((content, throwable) -> {
final Response result;
if (throwable == null && content.isPresent()) {
result = new RsWithBody(StandardRs.OK, new Content.From(content.get()));
} else {
result = StandardRs.NOT_FOUND;
}
return result;
})));
}
use of com.artipie.http.Headers in project maven-adapter by artipie.
the class HeadProxySliceTest method passesStatusAndHeadersFromResponse.
@Test
void passesStatusAndHeadersFromResponse() {
final RsStatus status = RsStatus.CREATED;
final Headers.From headers = new Headers.From("abc", "123");
MatcherAssert.assertThat(new HeadProxySlice(new SliceSimple(new RsWithHeaders(new RsWithStatus(status), headers))), new SliceHasResponse(Matchers.allOf(new RsHasStatus(status), new RsHasHeaders(headers)), new RequestLine(RqMethod.HEAD, "/")));
}
Aggregations