8784: Correct wget args, tweak styles.
authorTom Clegg <tom@curoverse.com>
Mon, 12 Jun 2017 20:59:09 +0000 (16:59 -0400)
committerTom Clegg <tom@curoverse.com>
Tue, 13 Jun 2017 14:48:17 +0000 (10:48 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curoverse.com>

services/keep-web/handler.go
services/keep-web/handler_test.go

index a37cfb70b366ef0fa700caeb375c22e461cce76f..be6049a2826ec555331db2894c93b96fbc0bfd2d 100644 (file)
@@ -340,7 +340,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
        } else if stat.IsDir() && !strings.HasSuffix(r.URL.Path, "/") {
                h.seeOtherWithCookie(w, r, basename+"/", credentialsOK)
        } else if stat.IsDir() {
-               h.serveDirectory(w, r, &coll, fs, openPath)
+               h.serveDirectory(w, r, &coll, fs, openPath, stripParts)
        } else {
                http.ServeContent(w, r, basename, stat.ModTime(), f)
                if int64(w.WroteBodyBytes()) != stat.Size() {
@@ -352,7 +352,27 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 }
 
 var dirListingTemplate = `<!DOCTYPE HTML>
-<HTML><HEAD><TITLE>{{ .Collection.Name }}</TITLE></HEAD>
+<HTML><HEAD>
+  <META name="robots" content="NOINDEX">
+  <TITLE>{{ .Collection.Name }}</TITLE>
+  <STYLE type="text/css">
+    body {
+      margin: 1.5em;
+    }
+    pre {
+      background-color: #D9EDF7;
+      border-radius: .25em;
+      padding: .75em;
+      overflow: auto;
+    }
+    .footer p {
+      font-size: 82%;
+    }
+    ul li {
+      font-family: monospace;
+    }
+  </STYLE>
+</HEAD>
 <BODY>
 <H1>{{ .Collection.Name }}</H1>
 
@@ -360,7 +380,7 @@ var dirListingTemplate = `<!DOCTYPE HTML>
 Arvados.  You can download individual files listed below.  To download
 the entire collection with wget, try:</P>
 
-<PRE>$ wget --mirror --no-parent --no-host --cut-dirs={{ .Request.URL }}</PRE>
+<PRE>$ wget --mirror --no-parent --no-host --cut-dirs={{ .StripParts }} https://{{ .Request.Host }}{{ .Request.URL }}</PRE>
 
 <H2>File Listing</H2>
 
@@ -368,9 +388,10 @@ the entire collection with wget, try:</P>
 {{range .Files}}  <LI><A href="{{.}}">{{.}}</A></LI>{{end}}
 </UL>
 
+<HR noshade>
 <DIV class="footer">
-  <H2>About Arvados</H2>
   <P>
+    About Arvados:
     Arvados is a free and open source software bioinformatics platform.
     To learn more, visit arvados.org.
     Arvados is not responsible for the files listed on this page.
@@ -380,7 +401,7 @@ the entire collection with wget, try:</P>
 </BODY>
 `
 
-func (h *handler) serveDirectory(w http.ResponseWriter, r *http.Request, collection *arvados.Collection, fs http.FileSystem, base string) {
+func (h *handler) serveDirectory(w http.ResponseWriter, r *http.Request, collection *arvados.Collection, fs http.FileSystem, base string, stripParts int) {
        var files []string
        var walk func(string) error
        if !strings.HasSuffix(base, "/") {
@@ -426,6 +447,7 @@ func (h *handler) serveDirectory(w http.ResponseWriter, r *http.Request, collect
                "Collection": collection,
                "Files":      files,
                "Request":    r,
+               "StripParts": stripParts,
        })
 }
 
index 508c9cb21e382f115ec0b5422f342a42614b7bbd..d3946590339bbc071476aaadb957dbd1a607b09c 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "fmt"
        "html"
        "io/ioutil"
        "net/http"
@@ -486,49 +487,58 @@ func (s *IntegrationSuite) TestDirectoryListing(c *check.C) {
                "Authorization": {"OAuth2 " + arvadostest.ActiveToken},
        }
        for _, trial := range []struct {
-               uri    string
-               header http.Header
-               expect []string
+               uri     string
+               header  http.Header
+               expect  []string
+               cutDirs int
        }{
                {
-                       uri:    strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + ".example.com/",
-                       header: authHeader,
-                       expect: []string{"dir1/foo", "dir1/bar"},
+                       uri:     strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + ".example.com/",
+                       header:  authHeader,
+                       expect:  []string{"dir1/foo", "dir1/bar"},
+                       cutDirs: 0,
                },
                {
-                       uri:    strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + ".example.com/dir1/",
-                       header: authHeader,
-                       expect: []string{"foo", "bar"},
+                       uri:     strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + ".example.com/dir1/",
+                       header:  authHeader,
+                       expect:  []string{"foo", "bar"},
+                       cutDirs: 0,
                },
                {
-                       uri:    "download.example.com/collections/" + arvadostest.FooAndBarFilesInDirUUID + "/",
-                       header: authHeader,
-                       expect: []string{"dir1/foo", "dir1/bar"},
+                       uri:     "download.example.com/collections/" + arvadostest.FooAndBarFilesInDirUUID + "/",
+                       header:  authHeader,
+                       expect:  []string{"dir1/foo", "dir1/bar"},
+                       cutDirs: 2,
                },
                {
-                       uri:    "collections.example.com/collections/download/" + arvadostest.FooAndBarFilesInDirUUID + "/" + arvadostest.ActiveToken + "/",
-                       header: nil,
-                       expect: []string{"dir1/foo", "dir1/bar"},
+                       uri:     "collections.example.com/collections/download/" + arvadostest.FooAndBarFilesInDirUUID + "/" + arvadostest.ActiveToken + "/",
+                       header:  nil,
+                       expect:  []string{"dir1/foo", "dir1/bar"},
+                       cutDirs: 4,
                },
                {
-                       uri:    "collections.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/",
-                       header: nil,
-                       expect: []string{"dir1/foo", "dir1/bar"},
+                       uri:     "collections.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/",
+                       header:  nil,
+                       expect:  []string{"dir1/foo", "dir1/bar"},
+                       cutDirs: 2,
                },
                {
-                       uri:    "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/dir1/",
-                       header: authHeader,
-                       expect: []string{"foo", "bar"},
+                       uri:     "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/dir1/",
+                       header:  authHeader,
+                       expect:  []string{"foo", "bar"},
+                       cutDirs: 1,
                },
                {
-                       uri:    "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/_/dir1/",
-                       header: authHeader,
-                       expect: []string{"foo", "bar"},
+                       uri:     "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/_/dir1/",
+                       header:  authHeader,
+                       expect:  []string{"foo", "bar"},
+                       cutDirs: 2,
                },
                {
-                       uri:    arvadostest.FooAndBarFilesInDirUUID + ".example.com/dir1?api_token=" + arvadostest.ActiveToken,
-                       header: authHeader,
-                       expect: []string{"foo", "bar"},
+                       uri:     arvadostest.FooAndBarFilesInDirUUID + ".example.com/dir1?api_token=" + arvadostest.ActiveToken,
+                       header:  authHeader,
+                       expect:  []string{"foo", "bar"},
+                       cutDirs: 0,
                },
                {
                        uri:    "collections.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/theperthcountyconspiracydoesnotexist/",
@@ -571,6 +581,7 @@ func (s *IntegrationSuite) TestDirectoryListing(c *check.C) {
                        for _, e := range trial.expect {
                                c.Check(resp.Body.String(), check.Matches, `(?ms).*href="`+e+`".*`)
                        }
+                       c.Check(resp.Body.String(), check.Matches, `(?ms).*--cut-dirs=`+fmt.Sprintf("%d", trial.cutDirs)+` .*`)
                }
        }
 }