@cryptotaxi247 / kubo / commits / c36e8dd04

gateway: reordered headers to avoid error

cc @mappum

Juan Batiz-Benet committed Jan 28, 2015 at 13:10 UTC c36e8dd04c326bd38f1cff5f196efbba72050240
1 file changed +11 -8
core/corehttp/gateway_handler.go
+11 -8
@@ -135,11 +135,20 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
135 return
136 }
137
138 - w.Header().Set("Etag", etag)
138 w.Header().Set("X-IPFS-Path", p)
140 - w.Header().Set("Cache-Control", "public, max-age=29030400")
139
140 dr, err := i.NewDagReader(nd)
141 + if err != nil && err != uio.ErrIsDir {
142 + // not a directory and still an error
143 + internalWebError(w, err)
144 + return
145 + }
146 +
147 + // set these headers _after_ the error, for we may just not have it
148 + // and dont want the client to cache a 500 response...
149 + w.Header().Set("Etag", etag)
150 + w.Header().Set("Cache-Control", "public, max-age=29030400")
151 +
152 if err == nil {
153 defer dr.Close()
154 _, name := path.Split(urlPath)
@@ -149,12 +158,6 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
158 return
159 }
160
152 - if err != uio.ErrIsDir {
153 - // not a directory and still an error
154 - internalWebError(w, err)
155 - return
156 - }
157 -
161 // storage for directory listing
162 var dirListing []directoryItem
163 // loop through files