Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:59:02+00:00 2026-05-26T04:59:02+00:00

Given a file being returned as part of a http request. What is the

  • 0

Given a file being returned as part of a http request. What is the correct method of creating an ETag for that file?

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19

I have seen it done several ways

  • Using the last write time of the file converted to ticks. Which is what NancyFX does https://github.com/NancyFx/Nancy/blob/master/src/Nancy/Responses/GenericFileResponse.cs
  • Using a hash of the file http://hartzer.wordpress.com/2009/10/04/client-side-caching/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:59:02+00:00Added an answer on May 26, 2026 at 4:59 am

    The answer is that it depends.

    There are two kinds of Etags, weak and strong ones. The weak ones let you do certain conditional operations, but most of them will require strong etags.

    The only restriction on a strong etag is that if the representation changes for whatever reason, so does the etag. If it’s a file you can generate a hash, but that forces you to keep the entity in-memory while you generate that. Alternatively, you could simply stream the content and add the Etag as a trailing http header, but nearly no server currently supports that (very useful and unloved) piece of functionality.

    Ticks have a low resolution, and it is possible that two contiguous writes on the same file will have the same number of ticks, even though the content is different. At that stage, the etag is now invalid if it was strong and you’re in muddy water. Same issue as with Last-Modified really. The way most HTTP servers deal with that is to give a file an etag based on multiple of its properties, aka timestamp, size and probably file object ID (inode in apache, probably adding the full path to the object store entry on NT, and IIS adds a counter to that value too so two config changes on a server would generate different etags, in case something changes).

    If you use some sort of database, the id + version ought to be a strong etag (provided, again, that the content you ahve is not an aggregate of multiple things that each may change independently without the root changing versions too).

    So how to calculate it really depends on your scenario, and persisting a hash of the file on write (before starting serving) will probably help you the most, especially as it’s a very useful feature to have for many other reasons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program that searches entire drives for a given file. At
Given a FILE*, is it possible to determine the underlying type? That is, is
Given a file path such as: \\server\folder_A\folder_B\etc\more.mov I need a regex that'll give me
Given a postscript file that has the following header %!PS-Adobe-3.0 I would like to
My goal is to be able to, being given a file/folder and a password,
Given a music file, is it possible to split out each instrument that is
Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why
I have to search a given file name (let say Keyword) in a directory
i want to find the mime-type for a given file extension on an IIS
I have a functionality where a user is given file to download. It works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.