FAQ
I want to use etags to reduce bandwidth - are there build in
etags in standard web server?

--

Search Discussions

  • Minux at Dec 14, 2012 at 5:40 pm

    On Sat, Dec 15, 2012 at 1:37 AM, thstart wrote:

    I want to use etags to reduce bandwidth - are there build in
    etags in standard web server?
    if your handle use http.ServeContent to serve content and set ETag in header
    before calling that, net/http will automatically handle some ETag related
    stuff
    for you (If-Non-Match, for example)

    --
  • Thstart at Dec 14, 2012 at 5:51 pm
    I am using following code:

    var webroot = flag.String("root", "/public", "web root directory")

    func handler(w http.ResponseWriter, r *http.Request) {
    ...
    }
    http.Handle("/images/", http.StripPrefix("",
    http.FileServer(http.Dir(*webroot))))
    http.HandleFunc("/", handler)
    http.ListenAndServe(listenAddr, nil)

    What I need to set so the etag be computed for the static files in webroot?
    On Friday, December 14, 2012 9:39:57 AM UTC-8, minux wrote:


    On Sat, Dec 15, 2012 at 1:37 AM, thstart <brag...@bragbuddy.com<javascript:>
    wrote:
    I want to use etags to reduce bandwidth - are there build in
    etags in standard web server?
    if your handle use http.ServeContent to serve content and set ETag in
    header
    before calling that, net/http will automatically handle some ETag related
    stuff
    for you (If-Non-Match, for example)
    --
  • Caleb Doxsey at Dec 15, 2012 at 9:42 pm
    You're going to have to write a custom handler instead of just using the
    built in FileServer. Something like:

    - Create a function to use with http.Handle("/images/", ...)
    - Make that function take the path the user sends in and translate it
    into the filename
    - Open the file and compute the hash of the file (might want to cache
    this...)
    - Add the ETag header
    - As minux said use ServeContent to send it back to the user

    ETags are sub-optimal. A better approach is to set the content to never
    expire and use a hash in the URL.

    http://blog.sendhub.com/post/36219926831/how-to-serve-django-statics-and-not-go-insane

    On Friday, December 14, 2012 9:51:12 AM UTC-8, thstart wrote:

    I am using following code:

    var webroot = flag.String("root", "/public", "web root directory")

    func handler(w http.ResponseWriter, r *http.Request) {
    ...
    }
    http.Handle("/images/", http.StripPrefix("",
    http.FileServer(http.Dir(*webroot))))
    http.HandleFunc("/", handler)
    http.ListenAndServe(listenAddr, nil)

    What I need to set so the etag be computed for the static files in webroot?
    On Friday, December 14, 2012 9:39:57 AM UTC-8, minux wrote:

    On Sat, Dec 15, 2012 at 1:37 AM, thstart wrote:

    I want to use etags to reduce bandwidth - are there build in
    etags in standard web server?
    if your handle use http.ServeContent to serve content and set ETag in
    header
    before calling that, net/http will automatically handle some ETag related
    stuff
    for you (If-Non-Match, for example)
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 14, '12 at 5:37p
activeDec 15, '12 at 9:42p
posts4
users3
websitegolang.org

3 users in discussion

Thstart: 2 posts Minux: 1 post Caleb Doxsey: 1 post

People

Translate

site design / logo © 2022 Grokbase