
com.artipie.http.rs.StandardRs Maven / Gradle / Ivy
/*
* The MIT License (MIT) Copyright (c) 2020-2023 artipie.com
* https://github.com/artipie/artipie/blob/master/LICENSE.txt
*/
package com.artipie.http.rs;
import com.artipie.asto.Content;
import com.artipie.http.Connection;
import com.artipie.http.Headers;
import com.artipie.http.Response;
import io.reactivex.Flowable;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletionStage;
/**
* Standard responses.
*/
public enum StandardRs implements Response {
/**
* Empty response.
*/
EMPTY(con -> con.accept(RsStatus.OK, Headers.EMPTY, new Content.From(Flowable.empty()))),
/**
* OK 200 response.
*/
OK(EMPTY),
/**
* Success response without content.
*/
NO_CONTENT(new RsWithStatus(RsStatus.NO_CONTENT)),
/**
* Not found response.
*/
NOT_FOUND(new RsWithStatus(RsStatus.NOT_FOUND)),
/**
* Not found with json.
*/
JSON_NOT_FOUND(
new RsWithBody(
new RsWithHeaders(
new RsWithStatus(RsStatus.NOT_FOUND),
Headers.from("Content-Type", "application/json")
),
ByteBuffer.wrap("{\"error\" : \"not found\"}".getBytes())
)
);
/**
* Origin response.
*/
private final Response origin;
/**
* Ctor.
* @param origin Origin response
*/
StandardRs(final Response origin) {
this.origin = origin;
}
@Override
public CompletionStage send(final Connection connection) {
return this.origin.send(connection);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy