Search in sources :

Example 6 with Response

use of com.artipie.http.Response in project maven-adapter by artipie.

the class PutMetadataChecksumSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Matcher matcher = PutMetadataChecksumSlice.PTN.matcher(new RequestLineFrom(line).uri().getPath());
    final Response res;
    if (matcher.matches()) {
        final String alg = matcher.group("alg");
        final String pkg = matcher.group("pkg");
        res = new AsyncResponse(this.findAndSave(body, alg, pkg).thenCompose(key -> {
            final CompletionStage<Response> resp;
            if (key.isPresent() && key.get().parent().isPresent() && key.get().parent().get().parent().isPresent()) {
                final Key location = key.get().parent().get().parent().get();
                // @checkstyle NestedIfDepthCheck (10 lines)
                resp = this.valid.ready(location).thenCompose(ready -> {
                    final CompletionStage<Response> action;
                    if (ready) {
                        action = this.validateAndUpdate(pkg, location);
                    } else {
                        action = CompletableFuture.completedFuture(new RsWithStatus(RsStatus.CREATED));
                    }
                    return action;
                });
            } else {
                resp = CompletableFuture.completedFuture(PutMetadataChecksumSlice.BAD_REQUEST);
            }
            return resp;
        }));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) ContentDigest(com.artipie.asto.ext.ContentDigest) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Single(io.reactivex.Single) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Map(java.util.Map) Observable(io.reactivex.Observable) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Maven(com.artipie.maven.Maven) RsWithStatus(com.artipie.http.rs.RsWithStatus) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) StandardCharsets(java.nio.charset.StandardCharsets) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) ValidUpload(com.artipie.maven.ValidUpload) PublisherAs(com.artipie.asto.ext.PublisherAs) CompletionStage(java.util.concurrent.CompletionStage) RxStorageWrapper(com.artipie.asto.rx.RxStorageWrapper) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) RsWithStatus(com.artipie.http.rs.RsWithStatus) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Example 7 with Response

use of com.artipie.http.Response in project maven-adapter by artipie.

the class HeadProxySlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final CompletableFuture<Response> promise = new CompletableFuture<>();
    this.client.response(line, Headers.EMPTY, Content.EMPTY).send((status, rsheaders, rsbody) -> {
        promise.complete(new RsWithHeaders(new RsWithStatus(status), rsheaders));
        return CompletableFuture.allOf();
    });
    return new AsyncResponse(promise);
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) CompletableFuture(java.util.concurrent.CompletableFuture) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) AsyncResponse(com.artipie.http.async.AsyncResponse)

Example 8 with Response

use of com.artipie.http.Response in project maven-adapter by artipie.

the class LocalMavenSlice method response.

@Override
public Response response(final String line, final Iterable<Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom rline = new RequestLineFrom(line);
    final Key key = new KeyFromPath(rline.uri().getPath());
    final Matcher match = LocalMavenSlice.PTN_ARTIFACT.matcher(new KeyLastPart(key).get());
    final Response response;
    if (match.matches()) {
        response = this.artifactResponse(rline.method(), key);
    } else {
        response = this.plainResponse(rline.method(), key);
    }
    return response;
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) KeyFromPath(com.artipie.http.slice.KeyFromPath) Matcher(java.util.regex.Matcher) KeyLastPart(com.artipie.asto.ext.KeyLastPart) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Key(com.artipie.asto.Key)

Example 9 with Response

use of com.artipie.http.Response in project artipie by artipie.

the class ContentLengthRestrictionTest method shouldPassRequestsWithinLimit.

@ParameterizedTest
@CsvSource({ "10,0", "10,not number", "10,1", "10,10" })
public void shouldPassRequestsWithinLimit(final int limit, final String value) {
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", this.headers(value), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.OK));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Response

use of com.artipie.http.Response in project artipie by artipie.

the class ContentLengthRestrictionTest method shouldPassRequestsWithoutContentLength.

@Test
public void shouldPassRequestsWithoutContentLength() {
    final int limit = 10;
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", Collections.emptySet(), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.OK));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Response (com.artipie.http.Response)10 RsWithStatus (com.artipie.http.rs.RsWithStatus)7 Slice (com.artipie.http.Slice)6 AsyncResponse (com.artipie.http.async.AsyncResponse)5 Key (com.artipie.asto.Key)4 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)4 ByteBuffer (java.nio.ByteBuffer)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Matcher (java.util.regex.Matcher)4 Content (com.artipie.asto.Content)3 RsHasStatus (com.artipie.http.hm.RsHasStatus)3 RsStatus (com.artipie.http.rs.RsStatus)3 KeyFromPath (com.artipie.http.slice.KeyFromPath)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Pattern (java.util.regex.Pattern)3 Test (org.junit.jupiter.api.Test)3 Publisher (org.reactivestreams.Publisher)3 Storage (com.artipie.asto.Storage)2 Digests (com.artipie.asto.ext.Digests)2