com.artipie.nuget.http.ResourceFromSlice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nuget-adapter Show documentation
Show all versions of nuget-adapter Show documentation
Turns your files/objects into NuGet artifacts
/*
* The MIT License (MIT) Copyright (c) 2020-2023 artipie.com
* https://github.com/artipie/artipie/blob/master/LICENSE.txt
*/
package com.artipie.nuget.http;
import com.artipie.asto.Content;
import com.artipie.http.Headers;
import com.artipie.http.Response;
import com.artipie.http.Slice;
import com.artipie.http.rq.RequestLine;
import com.artipie.http.rq.RqMethod;
import java.util.concurrent.CompletableFuture;
/**
* Resource created from {@link Slice}.
*/
final class ResourceFromSlice implements Resource {
/**
* Path to resource.
*/
private final String path;
/**
* Origin slice.
*/
private final Slice origin;
/**
* Ctor.
*
* @param path Path to resource.
* @param origin Origin slice.
*/
ResourceFromSlice(final String path, final Slice origin) {
this.path = path;
this.origin = origin;
}
@Override
public CompletableFuture get(Headers headers) {
return this.delegate(RqMethod.GET, headers, Content.EMPTY);
}
@Override
public CompletableFuture put(Headers headers, Content body) {
return this.delegate(RqMethod.PUT, headers, body);
}
/**
* Delegates request handling to origin slice.
*
* @param method Request method.
* @param headers Request headers.
* @param body Request body.
* @return Response generated by origin slice.
*/
private CompletableFuture delegate(RqMethod method, Headers headers, Content body) {
return this.origin.response(
new RequestLine(method.value(), this.path), headers, body
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy