use of com.artipie.http.rq.RequestLineFrom in project artipie by artipie.
the class DockerRoutingSlice 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 String path = req.uri().getPath();
final Matcher matcher = PTN_PATH.matcher(path);
final Response rsp;
if (matcher.matches()) {
final String group = matcher.group(1);
if (group.isEmpty() || group.equals("/")) {
rsp = new AsyncResponse(this.settings.auth().thenApply(auth -> new BasicAuthSlice(new BaseEntity(), auth, user -> !user.equals(Permissions.ANY_USER)).response(line, headers, body)));
} else {
rsp = this.origin.response(new RequestLine(req.method().toString(), new URIBuilder(req.uri()).setPath(group).toString(), req.version()).toString(), new Headers.From(headers, DockerRoutingSlice.HDR_REAL_PATH, path), body);
}
} else {
rsp = this.origin.response(line, headers, body);
}
return rsp;
}
use of com.artipie.http.rq.RequestLineFrom 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.rq.RequestLineFrom 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.rq.RequestLineFrom 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.rq.RequestLineFrom 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;
}
Aggregations