question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

enhance api for ConditionalHeaders usage

See original GitHub issue

sorry if there is already an appropriate way of doing this what I’m going to ask for. Since the documentation is lacking with respect to the usage of the ConditionalHeaders feature I coulnd’t find a way of managing it concisely. As far as I could see, in order to utilize ConditionalHeaders the OutgoingContent’s headers need to be set. Thus this here

// somewhere in installation phase
    install(ContentNegotiation) {
        register(ContentType.Application.Json, GsonConverter())
    }
    install(ConditionalHeaders)

// somewhere in api call
ctx.call.response.header(HttpHeaders.LastModified, lastModifiedTime)
ctx.call.respond(HttpStatusCode.OK, anydata)

don’t have any effect since the header of the ApplicationResponse is set (instead of the content). Therefore when I use ContentNegotiation I would need to adapt the conversion process so that the produced OutgoingContent instances also contain the relevant headers which is imho against the concise api nature of ktor.

wouldn’t it make sense that ApplicationResponse headers are applied to the OutgoingContent headers?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cy6erGn0mcommented, Nov 6, 2018

I see only two options (we probably need both):

  • a content converter need to know how to extract lastModified/etag from a data object
  • conditional headers feature could check both content and response headers

The second one is easy to implement while the first requires design

1reaction
cy6erGn0mcommented, Nov 6, 2018

@soywiz it’s not documented btw, need to notice it here https://ktor.io/servers/features/conditional-headers.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation/Best practices/Conditional requests - API Portal
When present, ETags are the preferred method for conditional requests. However, to improve API efficiency, some endpoints do not support ETags.
Read more >
Specifying Conditional Headers | Microsoft Learn
If a request specifies both the If-Match and If-Unmodified-Since headers, the request is evaluated based on the criteria specified in If-Match .
Read more >
HTTP conditional requests - MDN Web Docs - Mozilla
All conditional headers try to check if the resource stored on the server matches a specific version. To achieve this, the conditional ......
Read more >
Building Fast and Robust REST APIs using Conditional HTTP ...
Conditional HTTP requests are one of the little-known but widely used features. An intelligent client can determine the status and content ...
Read more >
2.3 Identify ways to optimize API usage through HTTP cache ...
HTTP Conditional Requests · - “If-Match”: Set to previously known “ETag” value. The condition is true if the ETag of the resource on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found