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));
}
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));
}
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));
}
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;
})));
}
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);
}
Aggregations