Skip to content

Commit 7210fc2

Browse files
author
hellojukay
committed
fix build error
1 parent c43f097 commit 7210fc2

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

Diff for: fs.go

+45-45
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"log"
1515
"mime"
1616
"mime/multipart"
17-
. "net/http"
17+
"net/http"
1818
"net/textproto"
1919
"net/url"
2020
"os"
@@ -107,11 +107,11 @@ type File interface {
107107
Stat() (os.FileInfo, error)
108108
}
109109

110-
func dirList(w ResponseWriter, r *Request, f File) {
110+
func dirList(w http.ResponseWriter, r *http.Request, f File) {
111111
dirs, err := f.Readdir(-1)
112112
if err != nil {
113113
logf(r, "http: error reading directory: %v", err)
114-
Error(w, "Error reading directory", StatusInternalServerError)
114+
http.Error(w, "Error reading directory", http.StatusInternalServerError)
115115
return
116116
}
117117
sort.Slice(dirs, func(i, j int) bool { return dirs[i].Name() < dirs[j].Name() })
@@ -163,7 +163,7 @@ func dirList(w ResponseWriter, r *Request, f File) {
163163
// ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.
164164
//
165165
// Note that *os.File implements the io.ReadSeeker interface.
166-
func ServeContent(w ResponseWriter, req *Request, name string, modtime time.Time, content io.ReadSeeker) {
166+
func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker) {
167167
sizeFunc := func() (int64, error) {
168168
size, err := content.Seek(0, io.SeekEnd)
169169
if err != nil {
@@ -192,14 +192,14 @@ var errNoOverlap = errors.New("invalid range: failed to overlap")
192192
// if modtime.IsZero(), modtime is unknown.
193193
// content must be seeked to the beginning of the file.
194194
// The sizeFunc is called at most once. Its error, if any, is sent in the HTTP response.
195-
func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time, sizeFunc func() (int64, error), content io.ReadSeeker) {
195+
func serveContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, sizeFunc func() (int64, error), content io.ReadSeeker) {
196196
setLastModified(w, modtime)
197197
done, rangeReq := checkPreconditions(w, r, modtime)
198198
if done {
199199
return
200200
}
201201

202-
code := StatusOK
202+
code := http.StatusOK
203203

204204
// If Content-Type isn't set, use the file's extension to find it, but
205205
// if the Content-Type is unset explicitly, do not sniff the type.
@@ -211,10 +211,10 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
211211
// read a chunk to decide between utf-8 text and binary
212212
var buf [sniffLen]byte
213213
n, _ := io.ReadFull(content, buf[:])
214-
ctype = DetectContentType(buf[:n])
214+
ctype = http.DetectContentType(buf[:n])
215215
_, err := content.Seek(0, io.SeekStart) // rewind to output whole file
216216
if err != nil {
217-
Error(w, "seeker can't seek", StatusInternalServerError)
217+
http.Error(w, "seeker can't seek", http.StatusInternalServerError)
218218
return
219219
}
220220
}
@@ -225,7 +225,7 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
225225

226226
size, err := sizeFunc()
227227
if err != nil {
228-
Error(w, err.Error(), StatusInternalServerError)
228+
http.Error(w, err.Error(), http.StatusInternalServerError)
229229
return
230230
}
231231

@@ -238,7 +238,7 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
238238
if err == errNoOverlap {
239239
w.Header().Set("Content-Range", fmt.Sprintf("bytes */%d", size))
240240
}
241-
Error(w, err.Error(), StatusRequestedRangeNotSatisfiable)
241+
http.Error(w, err.Error(), http.StatusRequestedRangeNotSatisfiable)
242242
return
243243
}
244244
if sumRangesSize(ranges) > size {
@@ -263,15 +263,15 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
263263
// multipart responses."
264264
ra := ranges[0]
265265
if _, err := content.Seek(ra.start, io.SeekStart); err != nil {
266-
Error(w, err.Error(), StatusRequestedRangeNotSatisfiable)
266+
http.Error(w, err.Error(), http.StatusRequestedRangeNotSatisfiable)
267267
return
268268
}
269269
sendSize = ra.length
270-
code = StatusPartialContent
270+
code = http.StatusPartialContent
271271
w.Header().Set("Content-Range", ra.contentRange(size))
272272
case len(ranges) > 1:
273273
sendSize = rangesMIMESize(ranges, ctype, size)
274-
code = StatusPartialContent
274+
code = http.StatusPartialContent
275275

276276
pr, pw := io.Pipe()
277277
mw := multipart.NewWriter(pw)
@@ -362,7 +362,7 @@ const (
362362
condFalse
363363
)
364364

365-
func checkIfMatch(w ResponseWriter, r *Request) condResult {
365+
func checkIfMatch(w http.ResponseWriter, r *http.Request) condResult {
366366
im := r.Header.Get("If-Match")
367367
if im == "" {
368368
return condNone
@@ -392,12 +392,12 @@ func checkIfMatch(w ResponseWriter, r *Request) condResult {
392392
return condFalse
393393
}
394394

395-
func checkIfUnmodifiedSince(r *Request, modtime time.Time) condResult {
395+
func checkIfUnmodifiedSince(r *http.Request, modtime time.Time) condResult {
396396
ius := r.Header.Get("If-Unmodified-Since")
397397
if ius == "" || isZeroTime(modtime) {
398398
return condNone
399399
}
400-
if t, err := ParseTime(ius); err == nil {
400+
if t, err := http.ParseTime(ius); err == nil {
401401
// The Date-Modified header truncates sub-second precision, so
402402
// use mtime < t+1s instead of mtime <= t to check for unmodified.
403403
if modtime.Before(t.Add(1 * time.Second)) {
@@ -408,7 +408,7 @@ func checkIfUnmodifiedSince(r *Request, modtime time.Time) condResult {
408408
return condNone
409409
}
410410

411-
func checkIfNoneMatch(w ResponseWriter, r *Request) condResult {
411+
func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) condResult {
412412
inm := get(r.Header, "If-None-Match")
413413
if inm == "" {
414414
return condNone
@@ -437,15 +437,15 @@ func checkIfNoneMatch(w ResponseWriter, r *Request) condResult {
437437
return condTrue
438438
}
439439

440-
func checkIfModifiedSince(r *Request, modtime time.Time) condResult {
440+
func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult {
441441
if r.Method != "GET" && r.Method != "HEAD" {
442442
return condNone
443443
}
444444
ims := r.Header.Get("If-Modified-Since")
445445
if ims == "" || isZeroTime(modtime) {
446446
return condNone
447447
}
448-
t, err := ParseTime(ims)
448+
t, err := http.ParseTime(ims)
449449
if err != nil {
450450
return condNone
451451
}
@@ -457,7 +457,7 @@ func checkIfModifiedSince(r *Request, modtime time.Time) condResult {
457457
return condTrue
458458
}
459459

460-
func checkIfRange(w ResponseWriter, r *Request, modtime time.Time) condResult {
460+
func checkIfRange(w http.ResponseWriter, r *http.Request, modtime time.Time) condResult {
461461
if r.Method != "GET" && r.Method != "HEAD" {
462462
return condNone
463463
}
@@ -478,7 +478,7 @@ func checkIfRange(w ResponseWriter, r *Request, modtime time.Time) condResult {
478478
if modtime.IsZero() {
479479
return condFalse
480480
}
481-
t, err := ParseTime(ir)
481+
t, err := http.ParseTime(ir)
482482
if err != nil {
483483
return condFalse
484484
}
@@ -495,13 +495,13 @@ func isZeroTime(t time.Time) bool {
495495
return t.IsZero() || t.Equal(unixEpochTime)
496496
}
497497

498-
func setLastModified(w ResponseWriter, modtime time.Time) {
498+
func setLastModified(w http.ResponseWriter, modtime time.Time) {
499499
if !isZeroTime(modtime) {
500-
w.Header().Set("Last-Modified", modtime.UTC().Format(TimeFormat))
500+
w.Header().Set("Last-Modified", modtime.UTC().Format(http.TimeFormat))
501501
}
502502
}
503503

504-
func writeNotModified(w ResponseWriter) {
504+
func writeNotModified(w http.ResponseWriter) {
505505
// RFC 7232 section 4.1:
506506
// a sender SHOULD NOT generate representation metadata other than the
507507
// above listed fields unless said metadata exists for the purpose of
@@ -513,19 +513,19 @@ func writeNotModified(w ResponseWriter) {
513513
if h.Get("Etag") != "" {
514514
delete(h, "Last-Modified")
515515
}
516-
w.WriteHeader(StatusNotModified)
516+
w.WriteHeader(http.StatusNotModified)
517517
}
518518

519519
// checkPreconditions evaluates request preconditions and reports whether a precondition
520520
// resulted in sending StatusNotModified or StatusPreconditionFailed.
521-
func checkPreconditions(w ResponseWriter, r *Request, modtime time.Time) (done bool, rangeHeader string) {
521+
func checkPreconditions(w http.ResponseWriter, r *http.Request, modtime time.Time) (done bool, rangeHeader string) {
522522
// This function carefully follows RFC 7232 section 6.
523523
ch := checkIfMatch(w, r)
524524
if ch == condNone {
525525
ch = checkIfUnmodifiedSince(r, modtime)
526526
}
527527
if ch == condFalse {
528-
w.WriteHeader(StatusPreconditionFailed)
528+
w.WriteHeader(http.StatusPreconditionFailed)
529529
return true, ""
530530
}
531531
switch checkIfNoneMatch(w, r) {
@@ -534,7 +534,7 @@ func checkPreconditions(w ResponseWriter, r *Request, modtime time.Time) (done b
534534
writeNotModified(w)
535535
return true, ""
536536
} else {
537-
w.WriteHeader(StatusPreconditionFailed)
537+
w.WriteHeader(http.StatusPreconditionFailed)
538538
return true, ""
539539
}
540540
case condNone:
@@ -552,7 +552,7 @@ func checkPreconditions(w ResponseWriter, r *Request, modtime time.Time) (done b
552552
}
553553

554554
// name is '/'-separated, not filepath.Separator.
555-
func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirect bool) {
555+
func serveFile(w http.ResponseWriter, r *http.Request, fs FileSystem, name string, redirect bool) {
556556
const indexPage = "/index.html"
557557

558558
// redirect .../index.html to .../
@@ -566,15 +566,15 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec
566566
f, err := fs.Open(name)
567567
if err != nil {
568568
msg, code := toHTTPError(err)
569-
Error(w, msg, code)
569+
http.Error(w, msg, code)
570570
return
571571
}
572572
defer f.Close()
573573

574574
d, err := f.Stat()
575575
if err != nil {
576576
msg, code := toHTTPError(err)
577-
Error(w, msg, code)
577+
http.Error(w, msg, code)
578578
return
579579
}
580580

@@ -625,7 +625,7 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec
625625
writeNotModified(w)
626626
return
627627
}
628-
w.Header().Set("Last-Modified", d.ModTime().UTC().Format(TimeFormat))
628+
w.Header().Set("Last-Modified", d.ModTime().UTC().Format(http.TimeFormat))
629629
dirList(w, r, f)
630630
return
631631
}
@@ -642,23 +642,23 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec
642642
// all errors. We don't want to start leaking information in error messages.
643643
func toHTTPError(err error) (msg string, httpStatus int) {
644644
if os.IsNotExist(err) {
645-
return "404 page not found", StatusNotFound
645+
return "404 page not found", http.StatusNotFound
646646
}
647647
if os.IsPermission(err) {
648-
return "403 Forbidden", StatusForbidden
648+
return "403 Forbidden", http.StatusForbidden
649649
}
650650
// Default:
651-
return "500 Internal Server Error", StatusInternalServerError
651+
return "500 Internal Server Error", http.StatusInternalServerError
652652
}
653653

654654
// localRedirect gives a Moved Permanently response.
655655
// It does not convert relative paths to absolute paths like Redirect does.
656-
func localRedirect(w ResponseWriter, r *Request, newPath string) {
656+
func localRedirect(w http.ResponseWriter, r *http.Request, newPath string) {
657657
if q := r.URL.RawQuery; q != "" {
658658
newPath += "?" + q
659659
}
660660
w.Header().Set("Location", newPath)
661-
w.WriteHeader(StatusMovedPermanently)
661+
w.WriteHeader(http.StatusMovedPermanently)
662662
}
663663

664664
// ServeFile replies to the request with the contents of the named
@@ -682,15 +682,15 @@ func localRedirect(w ResponseWriter, r *Request, newPath string) {
682682
// Outside of those two special cases, ServeFile does not use
683683
// r.URL.Path for selecting the file or directory to serve; only the
684684
// file or directory provided in the name argument is used.
685-
func ServeFile(w ResponseWriter, r *Request, name string) {
685+
func ServeFile(w http.ResponseWriter, r *http.Request, name string) {
686686
log.Printf("request method %s\n", r.Method)
687687
if containsDotDot(r.URL.Path) {
688688
// Too many programs use r.URL.Path to construct the argument to
689689
// serveFile. Reject the request under the assumption that happened
690690
// here and ".." may not be wanted.
691691
// Note that name might not contain "..", for example if code (still
692692
// incorrectly) used filepath.Join(myDir, r.URL.Path).
693-
Error(w, "invalid URL path", StatusBadRequest)
693+
http.Error(w, "invalid URL path", http.StatusBadRequest)
694694
return
695695
}
696696
dir, file := filepath.Split(name)
@@ -726,11 +726,11 @@ type fileHandler struct {
726726
// As a special case, the returned file server redirects any request
727727
// ending in "/index.html" to the same path, without the final
728728
// "index.html".
729-
func FileServer(root FileSystem) Handler {
729+
func FileServer(root FileSystem) http.Handler {
730730
return &fileHandler{root}
731731
}
732732

733-
func (f *fileHandler) ServeHTTP(w ResponseWriter, r *Request) {
733+
func (f *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
734734
upath := r.URL.Path
735735
if !strings.HasPrefix(upath, "/") {
736736
upath = "/" + upath
@@ -745,7 +745,7 @@ func (f *fileHandler) ServeHTTP(w ResponseWriter, r *Request) {
745745
}
746746

747747
// upload file
748-
func uploadFile(w ResponseWriter, r *Request, fs FileSystem, name string) {
748+
func uploadFile(w http.ResponseWriter, r *http.Request, fs FileSystem, name string) {
749749
r.ParseMultipartForm(32 << 20)
750750
file, handler, err := r.FormFile("file")
751751
if err != nil {
@@ -892,8 +892,8 @@ func sumRangesSize(ranges []httpRange) (size int64) {
892892
}
893893

894894
// is nil, logging is done via the log package's standard logger.
895-
func logf(r *Request, format string, args ...interface{}) {
896-
s, _ := r.Context().Value(ServerContextKey).(*Server)
895+
func logf(r *http.Request, format string, args ...interface{}) {
896+
s, _ := r.Context().Value(http.ServerContextKey).(*http.Server)
897897
if s != nil && s.ErrorLog != nil {
898898
s.ErrorLog.Printf(format, args...)
899899
} else {
@@ -914,7 +914,7 @@ var htmlReplacer = strings.NewReplacer(
914914
const sniffLen = 512
915915

916916
// get is like Get, but key must already be in CanonicalHeaderKey form.
917-
func get(h Header, key string) string {
917+
func get(h http.Header, key string) string {
918918
if v := h[key]; len(v) > 0 {
919919
return v[0]
920920
}

0 commit comments

Comments
 (0)