Search in sources :

Example 1 with RsFull

use of com.artipie.http.rs.RsFull in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldForwardRequestUnmodified.

@Test
void shouldForwardRequestUnmodified() {
    final Header header = new Header("header1", "value1");
    final byte[] body = "some code".getBytes();
    final RsStatus status = RsStatus.CREATED;
    MatcherAssert.assertThat(new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(status, rsheaders, rsbody), this.metrics).response(new RequestLine(RqMethod.POST, "/some_upload.war").toString(), new Headers.From(header), Flowable.just(ByteBuffer.wrap(body))), new ResponseMatcher(status, body, header));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) RsFull(com.artipie.http.rs.RsFull) Header(com.artipie.http.headers.Header) RsStatus(com.artipie.http.rs.RsStatus) Test(org.junit.jupiter.api.Test)

Example 2 with RsFull

use of com.artipie.http.rs.RsFull in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldForwardResponseUnmodified.

@Test
void shouldForwardResponseUnmodified() {
    final Header rsheader = new Header("header2", "value2");
    final byte[] body = "piece of code".getBytes();
    final RsStatus rsstatus = RsStatus.CREATED;
    final Response response = new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(rsstatus, new Headers.From(rsheader), Flowable.just(ByteBuffer.wrap(body))), this.metrics).response(new RequestLine(RqMethod.PUT, "/").toString(), Headers.EMPTY, Flowable.empty());
    MatcherAssert.assertThat(response, new ResponseMatcher(rsstatus, body, rsheader));
}
Also used : Response(com.artipie.http.Response) RqMethod(com.artipie.http.rq.RqMethod) BeforeEach(org.junit.jupiter.api.BeforeEach) RsWithStatus(com.artipie.http.rs.RsWithStatus) Headers(com.artipie.http.Headers) Header(com.artipie.http.headers.Header) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) CompletableFuture(java.util.concurrent.CompletableFuture) ByteBuffer(java.nio.ByteBuffer) RsFull(com.artipie.http.rs.RsFull) Test(org.junit.jupiter.api.Test) Authorization(com.artipie.http.headers.Authorization) RequestLine(com.artipie.http.rq.RequestLine) MatcherAssert(org.hamcrest.MatcherAssert) Flowable(io.reactivex.Flowable) IsEqual(org.hamcrest.core.IsEqual) RequestLine(com.artipie.http.rq.RequestLine) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) RsFull(com.artipie.http.rs.RsFull) Header(com.artipie.http.headers.Header) Headers(com.artipie.http.Headers) RsStatus(com.artipie.http.rs.RsStatus) Test(org.junit.jupiter.api.Test)

Example 3 with RsFull

use of com.artipie.http.rs.RsFull in project artipie by artipie.

the class PromuSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final String ctype = new Accept(headers).values().get(0);
    try (StringWriter writer = new StringWriter()) {
        final MetricsOutput output = new PrometheusOutput(writer, ctype, new HashSet<>(new RqParams(new RequestLineFrom(line).uri()).values("name")));
        this.metrics.publish(output);
        return new RsFull(RsStatus.OK, new Headers.From(new ContentType(ctype)), new Content.From(writer.toString().getBytes(StandardCharsets.UTF_8)));
    } catch (final IOException ioe) {
        throw new ArtipieIOException(ioe);
    }
}
Also used : Accept(com.artipie.http.headers.Accept) ContentType(com.artipie.http.headers.ContentType) ArtipieIOException(com.artipie.asto.ArtipieIOException) IOException(java.io.IOException) ArtipieIOException(com.artipie.asto.ArtipieIOException) RsFull(com.artipie.http.rs.RsFull) StringWriter(java.io.StringWriter) RqParams(com.artipie.http.rq.RqParams) Content(com.artipie.asto.Content) MetricsOutput(com.artipie.metrics.publish.MetricsOutput) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) PrometheusOutput(com.artipie.metrics.publish.PrometheusOutput)

Aggregations

RsFull (com.artipie.http.rs.RsFull)3 Header (com.artipie.http.headers.Header)2 ResponseMatcher (com.artipie.http.hm.ResponseMatcher)2 RequestLine (com.artipie.http.rq.RequestLine)2 RsStatus (com.artipie.http.rs.RsStatus)2 Test (org.junit.jupiter.api.Test)2 ArtipieIOException (com.artipie.asto.ArtipieIOException)1 Content (com.artipie.asto.Content)1 Headers (com.artipie.http.Headers)1 Response (com.artipie.http.Response)1 Accept (com.artipie.http.headers.Accept)1 Authorization (com.artipie.http.headers.Authorization)1 ContentType (com.artipie.http.headers.ContentType)1 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)1 RqMethod (com.artipie.http.rq.RqMethod)1 RqParams (com.artipie.http.rq.RqParams)1 RsWithStatus (com.artipie.http.rs.RsWithStatus)1 InMemoryMetrics (com.artipie.metrics.memory.InMemoryMetrics)1 MetricsOutput (com.artipie.metrics.publish.MetricsOutput)1 PrometheusOutput (com.artipie.metrics.publish.PrometheusOutput)1