Skip to content

Feature req: 'afterHeader' event or the ability to specify an ETag prefix #12

Description

@papandreou

I'm writing a piece of connect middleware similar to Apache's mod_negotiation. Based on req.url, the Accept-Language and Accept headers, a custom locale cookie, and which files are found on disc, it figures out which file to actually serve.

For example:

GET / HTTP/1.1
Cookie: language=fr
Accept: text/html

could get mapped to /index.fr.html, and

GET /someDir/foo.html HTTP/1.1
Accept-Language: nl, da

could get mapped to /someDir/foo.da.html -- unless a Dutch version of the file was also available.

I'd like to use send for this, or maybe just require that my module sits right above connect.static in the middleware stack.

Here's my problem -- since any given incoming url might map to different files on disc, which could very well have the same modification times and byte lengths, send's current ETag scheme won't work. If a client does a conditional GET request for a page after switching to a different language (either changing the language cookie or Accept-Language), it could lead to a "false positive" 304 response.

I know I can set the ETag header in my own code, and that's my current solution -- I use send's algorithm and append -<localeId> to the ETag. Unfortunately that means my server is doing 2 stat calls for each static file request, which I'm not a fan of.

So what I'd like instead is for send's setHeader to support adding to existing "ETag fragments", or alternatively an event being emitted after the headers have been set, but before the freshness check. This would be a nice spot: https://github.com/visionmedia/send/blob/master/lib/send.js#L348

What do you think? Is this use case too convoluted to warrant added complexity in send?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions