|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Oracle and/or its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.helidon.webserver.tests; |
| 17 | + |
| 18 | +import io.helidon.http.HeaderNames; |
| 19 | +import io.helidon.http.Status; |
| 20 | +import io.helidon.logging.common.LogConfig; |
| 21 | +import io.helidon.webclient.http1.Http1Client; |
| 22 | +import io.helidon.webclient.http1.Http1ClientResponse; |
| 23 | +import io.helidon.webserver.http.HttpRules; |
| 24 | +import io.helidon.webserver.testing.junit5.ServerTest; |
| 25 | +import io.helidon.webserver.testing.junit5.SetUpRoute; |
| 26 | + |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +import static org.hamcrest.CoreMatchers.is; |
| 30 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | + |
| 32 | +@ServerTest |
| 33 | +class ContentEncodingEmptyTest { |
| 34 | + |
| 35 | + private final Http1Client client; |
| 36 | + |
| 37 | + ContentEncodingEmptyTest(Http1Client client) { |
| 38 | + this.client = client; |
| 39 | + } |
| 40 | + |
| 41 | + @SetUpRoute |
| 42 | + static void routing(HttpRules rules) { |
| 43 | + LogConfig.configureRuntime(); |
| 44 | + rules.post("/hello", (req, res) -> { |
| 45 | + res.status(Status.NO_CONTENT_204); |
| 46 | + res.send(); // empty entity |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void gzipEncodeEmptyEntity() { |
| 52 | + Http1ClientResponse res = client.post("hello") |
| 53 | + .header(HeaderNames.CONTENT_TYPE, "application/json") |
| 54 | + .header(HeaderNames.ACCEPT_ENCODING, "gzip") |
| 55 | + .request(); |
| 56 | + assertThat(res.status().code(), is(204)); |
| 57 | + } |
| 58 | +} |
0 commit comments