We have enabled https in our micronaut application.
Controller file is as below
package http.caching.controllers
import io.micronaut.core.async.publisher.Publishers
import io.micronaut.http.HttpHeaders
import io.micronaut.http.HttpHeaders.CACHE_CONTROL
import io.micronaut.http.HttpHeaders.ETAG
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Controller("/api/v1/test/")
class MyController {
private val log: Logger = LoggerFactory.getLogger(this::class.java)
@Get
fun index(
request: HttpRequest<*>
): HttpResponse<String> {
val url = request.uri
log.info("Request url is $url")
val eTag = url.hashCode().toString()
val requestETag = request.headers.get(HttpHeaders.IF_NONE_MATCH)
if (requestETag != null && requestETag == eTag) {
log.info("Request url is $url")
log.info("ETag matches. Returning 304 - Not modified")
return HttpResponse.notModified<String?>().header(HttpHeaders.ETAG, eTag).header(
HttpHeaders.CACHE_CONTROL, "max-age=60")
}
val data = "Hello this is a test"
return HttpResponse.ok(data).header(ETAG, eTag).header(CACHE_CONTROL, "max-age=60")
}
}
application.yml file is as below
micronaut:
server:
cors:
enabled: true
ssl:
enabled: true
buildSelfSigned: true
netty:
default:
allocator:
max-order: 3
On hitting the API endpoint for the first time, as per controller logic, API response will contain Etag and Cache-control: max-age:60 headers
Expectation: On hitting the API endpoint for the second time, API request should contain "If-None-Match" header added by browser and as per the controller logic, response code should be 304.
Actual: The request does not contain "If-Non-Match" header.
NOTE: The headers work as expected if we remove the ssl configuration from application.yml and run the app with http.
Is there any explicit headers configuration we need to add for "HTTPS" ?