Search in sources :

Example 1 with Headers

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());
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) RepoConfig(com.artipie.repo.RepoConfig) Headers(com.artipie.http.Headers) IsNot(org.hamcrest.core.IsNot) Slice(com.artipie.http.Slice) Permissions(com.artipie.http.auth.Permissions) CustomMatcher(org.hamcrest.CustomMatcher) RsStatus(com.artipie.http.rs.RsStatus) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) RsHasStatus(com.artipie.http.hm.RsHasStatus) RequestLine(com.artipie.http.rq.RequestLine) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Flowable(io.reactivex.Flowable) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) MethodSource(org.junit.jupiter.params.provider.MethodSource) RequestLine(com.artipie.http.rq.RequestLine) Slice(com.artipie.http.Slice) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with Headers

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;
    })));
}
Also used : Header(com.artipie.http.headers.Header) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Hex(org.apache.commons.codec.binary.Hex) DigestVerification(com.artipie.asto.cache.DigestVerification) RsWithBody(com.artipie.http.rs.RsWithBody) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Flowable(io.reactivex.Flowable) Locale(java.util.Locale) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Remote(com.artipie.asto.cache.Remote) KeyFromPath(com.artipie.http.slice.KeyFromPath) Headers(com.artipie.http.Headers) DecoderException(org.apache.commons.codec.DecoderException) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Cache(com.artipie.asto.cache.Cache) Pattern(java.util.regex.Pattern) StandardRs(com.artipie.http.rs.StandardRs) CacheControl(com.artipie.asto.cache.CacheControl) Optional(java.util.Optional) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) ByteBuffer(java.nio.ByteBuffer) RsWithBody(com.artipie.http.rs.RsWithBody) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) CompletableFuture(java.util.concurrent.CompletableFuture) KeyFromPath(com.artipie.http.slice.KeyFromPath) Content(com.artipie.asto.Content) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 3 with Headers

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, "/")));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) Headers(com.artipie.http.Headers) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsStatus(com.artipie.http.rs.RsStatus) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Aggregations

Headers (com.artipie.http.Headers)3 Key (com.artipie.asto.Key)2 Slice (com.artipie.http.Slice)2 RsHasStatus (com.artipie.http.hm.RsHasStatus)2 RequestLine (com.artipie.http.rq.RequestLine)2 RsStatus (com.artipie.http.rs.RsStatus)2 Flowable (io.reactivex.Flowable)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Yaml (com.amihaiemil.eoyaml.Yaml)1 Content (com.artipie.asto.Content)1 Cache (com.artipie.asto.cache.Cache)1 CacheControl (com.artipie.asto.cache.CacheControl)1 DigestVerification (com.artipie.asto.cache.DigestVerification)1 Remote (com.artipie.asto.cache.Remote)1 Digests (com.artipie.asto.ext.Digests)1 Response (com.artipie.http.Response)1 AsyncResponse (com.artipie.http.async.AsyncResponse)1 Permissions (com.artipie.http.auth.Permissions)1 ClientSlices (com.artipie.http.client.ClientSlices)1