Search in sources :

Example 1 with Header

use of com.artipie.http.headers.Header 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 Header

use of com.artipie.http.headers.Header 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 Header

use of com.artipie.http.headers.Header in project artipie by artipie.

the class PromuSliceTest method returnsMetricsThatMatchNames.

@Test
void returnsMetricsThatMatchNames() {
    final Metrics metrics = new InMemoryMetrics();
    metrics.counter("http.response.count").inc();
    metrics.gauge("http.response.content").set(5000L);
    metrics.gauge("app.workload").set(300L);
    MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new RsHasBody(new AnyOf<>(new IsEqual<>(String.join("\n", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "")), new IsEqual<>(String.join("\n", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", ""))), StandardCharsets.UTF_8), new RequestLine(RqMethod.GET, "/prometheus/metrics?name=http_response_content&name=app_workload"), new Headers.From(new Header(Accept.NAME, PromuSliceTest.PLAIN_TEXT)), Content.EMPTY));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Header

use of com.artipie.http.headers.Header in project maven-adapter by artipie.

the class CachedProxySlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom req = new RequestLineFrom(line);
    final Key key = new KeyFromPath(req.uri().getPath());
    return new AsyncResponse(new RepoHead(this.client).head(req.uri().getPath()).thenCompose(head -> this.cache.load(key, new Remote.WithErrorHandling(() -> {
        final CompletableFuture<Optional<? extends Content>> promise = new CompletableFuture<>();
        this.client.response(line, Headers.EMPTY, Content.EMPTY).send((rsstatus, rsheaders, rsbody) -> {
            final CompletableFuture<Void> term = new CompletableFuture<>();
            if (rsstatus.success()) {
                final Flowable<ByteBuffer> res = Flowable.fromPublisher(rsbody).doOnError(term::completeExceptionally).doOnTerminate(() -> term.complete(null));
                promise.complete(Optional.of(new Content.From(res)));
            } else {
                promise.complete(Optional.empty());
            }
            return term;
        });
        return promise;
    }), new CacheControl.All(StreamSupport.stream(head.orElse(Headers.EMPTY).spliterator(), false).map(Header::new).map(CachedProxySlice::checksumControl).collect(Collectors.toUnmodifiableList()))).handle((content, throwable) -> {
        final Response result;
        if (throwable == null && content.isPresent()) {
            result = new RsWithBody(StandardRs.OK, new Content.From(content.get()));
        } else {
            result = StandardRs.NOT_FOUND;
        }
        return result;
    })));
}
Also used : Header(com.artipie.http.headers.Header) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Hex(org.apache.commons.codec.binary.Hex) DigestVerification(com.artipie.asto.cache.DigestVerification) RsWithBody(com.artipie.http.rs.RsWithBody) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Flowable(io.reactivex.Flowable) Locale(java.util.Locale) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Remote(com.artipie.asto.cache.Remote) KeyFromPath(com.artipie.http.slice.KeyFromPath) Headers(com.artipie.http.Headers) DecoderException(org.apache.commons.codec.DecoderException) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Cache(com.artipie.asto.cache.Cache) Pattern(java.util.regex.Pattern) StandardRs(com.artipie.http.rs.StandardRs) CacheControl(com.artipie.asto.cache.CacheControl) Optional(java.util.Optional) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) ByteBuffer(java.nio.ByteBuffer) RsWithBody(com.artipie.http.rs.RsWithBody) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) CompletableFuture(java.util.concurrent.CompletableFuture) KeyFromPath(com.artipie.http.slice.KeyFromPath) Content(com.artipie.asto.Content) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 5 with Header

use of com.artipie.http.headers.Header in project maven-adapter by artipie.

the class ArtifactHeaders method checksumsHeader.

/**
 * Checksum headers.
 * @param checksums Artifact checksums
 * @return Checksum header and {@code ETag} header
 */
private static Headers checksumsHeader(final Map<String, String> checksums) {
    final ArrayList<Map.Entry<String, String>> headers = new ArrayList<>(checksums.size() + 1);
    for (final Map.Entry<String, String> entry : checksums.entrySet()) {
        headers.add(new Header(String.format("X-Checksum-%s", entry.getKey()), entry.getValue()));
    }
    Optional.ofNullable(checksums.get("sha1")).ifPresent(sha -> headers.add(new Header("ETag", sha)));
    return new Headers.From(headers);
}
Also used : Header(com.artipie.http.headers.Header) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

Header (com.artipie.http.headers.Header)6 RequestLine (com.artipie.http.rq.RequestLine)4 InMemoryMetrics (com.artipie.metrics.memory.InMemoryMetrics)3 Test (org.junit.jupiter.api.Test)3 Headers (com.artipie.http.Headers)2 Response (com.artipie.http.Response)2 ResponseMatcher (com.artipie.http.hm.ResponseMatcher)2 RsHasBody (com.artipie.http.hm.RsHasBody)2 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)2 RsFull (com.artipie.http.rs.RsFull)2 RsStatus (com.artipie.http.rs.RsStatus)2 Metrics (com.artipie.metrics.Metrics)2 Flowable (io.reactivex.Flowable)2 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 IsEqual (org.hamcrest.core.IsEqual)2 Content (com.artipie.asto.Content)1 Key (com.artipie.asto.Key)1 Cache (com.artipie.asto.cache.Cache)1