use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.
the class ResponseMetricsSliceTest method shouldReportInternalErrorResponse.
@Test
public void shouldReportInternalErrorResponse() {
this.send(RqMethod.POST, new RsWithStatus(RsStatus.INTERNAL_ERROR));
this.send(RqMethod.POST, new RsWithStatus(RsStatus.INTERNAL_ERROR));
MatcherAssert.assertThat(this.metrics.counter("post.error.internal").value(), new IsEqual<>(2L));
}
use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.
the class ContentLengthRestrictionTest method shouldNotPassRequestsAboveLimit.
@Test
public void shouldNotPassRequestsAboveLimit() {
final int limit = 10;
final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
final Response response = slice.response("", this.headers("11"), Flowable.empty());
MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.PAYLOAD_TOO_LARGE));
}
use of com.artipie.http.rs.RsWithStatus 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, "/")));
}
use of com.artipie.http.rs.RsWithStatus in project maven-adapter by artipie.
the class PutMetadataSlice method response.
@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final Response res;
final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
if (matcher.matches()) {
final Key pkg = new KeyFromPath(matcher.group("pkg"));
res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
final Key key;
if (snapshot.isPresent()) {
key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
} else {
key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
}
return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
}).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
} else {
res = new RsWithStatus(RsStatus.BAD_REQUEST);
}
return res;
}
use of com.artipie.http.rs.RsWithStatus 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;
}
Aggregations