Comments (8)
@gzoritchak Why don't you simply intercept and wrap LocalFileContent with your best max-age settings?
from ktor.
the other alternative is to provide constructor parameters expires and cache control
from ktor.
Why don't you simply intercept and wrap LocalFileContent with your best max-age settings?
I first tried to put a global interception :
intercept(ApplicationCallPipeline.Infrastructure) {
if (call.request.httpMethod == HttpMethod.Get ||
call.request.httpMethod == HttpMethod.Head) {
call.response.cacheControl(CacheControl.MaxAge(300))
}
}
It put the Cache-control header to all requests except the ones served by LocalFileContent.
the other alternative is to provide constructor parameters expires and cache control
I didn't see any constructor in LocalFileContent that gives access to cacheControl property.
from ktor.
My bad: the global interception is working.
In fact I have now 2 Cache-Control http header for one request!!
from ktor.
@gzoritchak in a simple case I see no double cache control header
from ktor.
- Thanks for your modifications on LocalFileContent to allow CacheControl.
- In your test, adding cache control to the LocalFileContent doubles the header. It should not be possible (https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2)
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.
fun testInterceptCacheControl() {
withTestApplication {
application.intercept(ApplicationCallPipeline.Infrastructure) { call ->
if (call.request.httpMethod == HttpMethod.Get ||
call.request.httpMethod == HttpMethod.Head) {
call.response.cacheControl(CacheControl.MaxAge(300))
}
}
application.intercept(ApplicationCallPipeline.Call) { call ->
call.respond(LocalFileContent(
File(basedir, "org/jetbrains/ktor/tests/http/StaticContentTest.kt"),
cacheControl = CacheControl.MaxAge(200)
))
}
produces the assertion fail:
java.lang.AssertionError:
Expected :[max-age=300]
Actual :[max-age=300, max-age=200]
But I don't know if it should be considered as a bug. Is it the responsibility of the developper to be sure of adding only one time the Cache-Control header? In fact it's a little bit more complicated. The Cache-Control can be added more than one time but for different directives.
I close this bug and let you decide if the duplicate header with same directive should be considered as a bug.
from ktor.
Don't think we can eliminate double headers: to achieve this we have to keep and maintain a list of single values only headers that doesn't look good
from ktor.
I'm not sure.
The specification gives a general rule that can be applied. It's not an implementation based like "THIS particular header can be duplicated and THAT one not".
from ktor.
Related Issues (20)
- Ktor/Netty hang up while Ktor/Jetty is fine HOT 2
- `Route.param()` is not work
- Random NPEs in CIOEngine HOT 1
- Invalid hex byte exception when decoding invalid query string HOT 1
- parameters in the builder is not configurable HOT 1
- Ktor works fine in Intellij but not on command line HOT 1
- Project 'tomcat-war' not found in root project HOT 5
- I have the same exception in version 1.6.2. HOT 2
- DefaultRequest Plugin - InvalidMutabilityException When Changing Anything Except Protocol - 2.0.0-beta-1 on iOS HOT 1
- Ktor server :: not working when application in background Android API 21 (5.0+) HOT 2
- Old version of jwt HOT 1
- Jetty Engine - Overwriting custom handlers HOT 1
- Could not find io.ktor:ktor-gson:2.0.2 HOT 2
- Dependency Dashboard
- Can't pass SSL handshake on KMM project
- CIO Request Timed Out on large files HOT 4
- question: why to set full url in packet instead of just query for proxy? HOT 4
- ReaderJob & WriterJob leak in TLS socket and prevent context from completion HOT 3
- Bearer auth token refresh hangs after prior refresh threw an exception HOT 1
- renderSetCookieHeader shouldn't ignore maxAge = 0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ktor.