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;
}
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);
}
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;
}
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));
}
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));
}
Aggregations