All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.artipie.nuget.http.ResourceFromSlice Maven / Gradle / Ivy

There is a newer version: 1.5.5
Show newest version
/*
 * 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