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.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 io.reactivex.Flowable;
import java.nio.ByteBuffer;
import org.reactivestreams.Publisher;

/**
 * Resource created from {@link Slice}.
 *
 * @since 0.2
 */
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 Response get(final Headers headers) {
        return this.delegate(RqMethod.GET, headers, Flowable.empty());
    }

    @Override
    public Response put(final Headers headers, final Publisher 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 Response delegate(
        final RqMethod method,
        final Headers headers,
        final Publisher body
    ) {
        return this.origin.response(
            new RequestLine(method.value(), this.path).toString(),
            headers,
            body
        );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy