]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: make FileServer look good on mobile
authorMax πŸ‘¨πŸ½β€πŸ’» Coplan <mchcopl@gmail.com>
Fri, 22 Dec 2023 19:38:29 +0000 (11:38 -0800)
committerGopher Robot <gobot@golang.org>
Sat, 24 Feb 2024 19:36:28 +0000 (19:36 +0000)
Currently when viewing directories on a phone, the text is small and
often hard to tap correctly.  This commit adds the viewport property to
the page to make it look correct on phones.  This commit also makes the
page behave in Standards Mode instead of Quirks Mode which does not
effect the behavior of this page but makes me feel good inside β˜ΊοΈ

Change-Id: I4babcf79085e85fba57453b7a235e4750a269a42
Reviewed-on: https://go-review.googlesource.com/c/go/+/552595
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Max Coplan <mchcopl@gmail.com>
src/net/http/fs.go
src/net/http/fs_test.go

index af7511a7a4bd7e317029ffda09fdd834d77c6da6..678b978b7bd6410f9176dcb800279763090a40db 100644 (file)
@@ -151,6 +151,8 @@ func dirList(w ResponseWriter, r *Request, f File) {
        sort.Slice(dirs, func(i, j int) bool { return dirs.name(i) < dirs.name(j) })
 
        w.Header().Set("Content-Type", "text/html; charset=utf-8")
+       fmt.Fprintf(w, "<!doctype html>\n")
+       fmt.Fprintf(w, "<meta name=\"viewport\" content=\"width=device-width\">\n")
        fmt.Fprintf(w, "<pre>\n")
        for i, n := 0, dirs.len(); i < n; i++ {
                name := dirs.name(i)
index 861e70caf23963199559142a77ece6aaae6aa5aa..383d27df9b1aba31f72c492cfe7da620e9d3f2e8 100644 (file)
@@ -325,7 +325,7 @@ func TestFileServerCleans(t *testing.T) {
 
 func TestFileServerEscapesNames(t *testing.T) { run(t, testFileServerEscapesNames) }
 func testFileServerEscapesNames(t *testing.T, mode testMode) {
-       const dirListPrefix = "<pre>\n"
+       const dirListPrefix = "<!doctype html>\n<meta name=\"viewport\" content=\"width=device-width\">\n<pre>\n"
        const dirListSuffix = "\n</pre>\n"
        tests := []struct {
                name, escaped string