Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(583)

Side by Side Diff: src/pkg/http/fs.go

Issue 4185053: code review 4185053: http: introduce Header type, implement with net/textproto (Closed)
Patch Set: diff -r 2058371f94f0 https://go.googlecode.com/hg/ Created 14 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/http/client.go ('k') | src/pkg/http/fs_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // HTTP file system request handler 5 // HTTP file system request handler
6 6
7 package http 7 package http
8 8
9 import ( 9 import (
10 "fmt" 10 "fmt"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return 97 return
98 } 98 }
99 } else { 99 } else {
100 if url[len(url)-1] == '/' { 100 if url[len(url)-1] == '/' {
101 Redirect(w, r, url[0:len(url)-1], StatusMovedPer manently) 101 Redirect(w, r, url[0:len(url)-1], StatusMovedPer manently)
102 return 102 return
103 } 103 }
104 } 104 }
105 } 105 }
106 106
107 » if t, _ := time.Parse(TimeFormat, r.Header["If-Modified-Since"]); t != n il && d.Mtime_ns/1e9 <= t.Seconds() { 107 » if t, _ := time.Parse(TimeFormat, r.Header.Get("If-Modified-Since")); t != nil && d.Mtime_ns/1e9 <= t.Seconds() {
108 w.WriteHeader(StatusNotModified) 108 w.WriteHeader(StatusNotModified)
109 return 109 return
110 } 110 }
111 w.SetHeader("Last-Modified", time.SecondsToUTC(d.Mtime_ns/1e9).Format(Ti meFormat)) 111 w.SetHeader("Last-Modified", time.SecondsToUTC(d.Mtime_ns/1e9).Format(Ti meFormat))
112 112
113 // use contents of index.html for directory, if present 113 // use contents of index.html for directory, if present
114 if d.IsDirectory() { 114 if d.IsDirectory() {
115 index := name + indexPage 115 index := name + indexPage
116 ff, err := os.Open(index, os.O_RDONLY, 0) 116 ff, err := os.Open(index, os.O_RDONLY, 0)
117 if err == nil { 117 if err == nil {
(...skipping 28 matching lines...) Expand all
146 if isText(b) { 146 if isText(b) {
147 w.SetHeader("Content-Type", "text-plain; charset=utf-8") 147 w.SetHeader("Content-Type", "text-plain; charset=utf-8")
148 } else { 148 } else {
149 w.SetHeader("Content-Type", "application/octet-stream") // generic binary 149 w.SetHeader("Content-Type", "application/octet-stream") // generic binary
150 } 150 }
151 f.Seek(0, 0) // rewind to output whole file 151 f.Seek(0, 0) // rewind to output whole file
152 } 152 }
153 153
154 // handle Content-Range header. 154 // handle Content-Range header.
155 // TODO(adg): handle multiple ranges 155 // TODO(adg): handle multiple ranges
156 » ranges, err := parseRange(r.Header["Range"], size) 156 » ranges, err := parseRange(r.Header.Get("Range"), size)
157 if err != nil || len(ranges) > 1 { 157 if err != nil || len(ranges) > 1 {
158 Error(w, err.String(), StatusRequestedRangeNotSatisfiable) 158 Error(w, err.String(), StatusRequestedRangeNotSatisfiable)
159 return 159 return
160 } 160 }
161 if len(ranges) == 1 { 161 if len(ranges) == 1 {
162 ra := ranges[0] 162 ra := ranges[0]
163 if _, err := f.Seek(ra.start, 0); err != nil { 163 if _, err := f.Seek(ra.start, 0); err != nil {
164 Error(w, err.String(), StatusRequestedRangeNotSatisfiabl e) 164 Error(w, err.String(), StatusRequestedRangeNotSatisfiabl e)
165 return 165 return
166 } 166 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if i >= size { 256 if i >= size {
257 i = size - 1 257 i = size - 1
258 } 258 }
259 r.length = i - r.start + 1 259 r.length = i - r.start + 1
260 } 260 }
261 } 261 }
262 ranges = append(ranges, r) 262 ranges = append(ranges, r)
263 } 263 }
264 return ranges, nil 264 return ranges, nil
265 } 265 }
OLDNEW
« no previous file with comments | « src/pkg/http/client.go ('k') | src/pkg/http/fs_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b