projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: subcommand not recognized in $0 when no CLI args are given.
[arvados.git]
/
services
/
keep-web
/
handler.go
diff --git
a/services/keep-web/handler.go
b/services/keep-web/handler.go
index 06185882dcd781bc133e0c42a0756dc31e21342e..517ec1a2a26e96967ad50bec925a65b1f6149f6a 100644
(file)
--- a/
services/keep-web/handler.go
+++ b/
services/keep-web/handler.go
@@
-10,10
+10,10
@@
import (
"html"
"html/template"
"io"
"html"
"html/template"
"io"
- "log"
"net/http"
"net/url"
"os"
"net/http"
"net/url"
"os"
+ "path/filepath"
"sort"
"strconv"
"strings"
"sort"
"strconv"
"strings"
@@
-25,6
+25,7
@@
import (
"git.curoverse.com/arvados.git/sdk/go/health"
"git.curoverse.com/arvados.git/sdk/go/httpserver"
"git.curoverse.com/arvados.git/sdk/go/keepclient"
"git.curoverse.com/arvados.git/sdk/go/health"
"git.curoverse.com/arvados.git/sdk/go/httpserver"
"git.curoverse.com/arvados.git/sdk/go/keepclient"
+ log "github.com/Sirupsen/logrus"
"golang.org/x/net/webdav"
)
"golang.org/x/net/webdav"
)
@@
-190,13
+191,12
@@
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
} else if w.WroteStatus() == 0 {
w.WriteHeader(statusCode)
} else if w.WroteStatus() != statusCode {
} else if w.WroteStatus() == 0 {
w.WriteHeader(statusCode)
} else if w.WroteStatus() != statusCode {
- httpserver.Log(r.RemoteAddr, "WARNING",
+ log.WithField("RequestID", r.Header.Get("X-Request-Id")).Warn(
fmt.Sprintf("Our status changed from %d to %d after we sent headers", w.WroteStatus(), statusCode))
}
if statusText == "" {
statusText = http.StatusText(statusCode)
}
fmt.Sprintf("Our status changed from %d to %d after we sent headers", w.WroteStatus(), statusCode))
}
if statusText == "" {
statusText = http.StatusText(statusCode)
}
- httpserver.Log(remoteAddr, statusCode, statusText, w.WroteBodyBytes(), r.Method, r.Host, r.URL.Path, r.URL.RawQuery)
}()
if strings.HasPrefix(r.URL.Path, "/_health/") && r.Method == "GET" {
}()
if strings.HasPrefix(r.URL.Path, "/_health/") && r.Method == "GET" {
@@
-313,6
+313,14
@@
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
return
}
return
}
+ if useSiteFS {
+ if tokens == nil {
+ tokens = auth.NewCredentialsFromHTTPRequest(r).Tokens
+ }
+ h.serveSiteFS(w, r, tokens, credentialsOK, attachment)
+ return
+ }
+
targetPath := pathParts[stripParts:]
if tokens == nil && len(targetPath) > 0 && strings.HasPrefix(targetPath[0], "t=") {
// http://ID.example/t=TOKEN/PATH...
targetPath := pathParts[stripParts:]
if tokens == nil && len(targetPath) > 0 && strings.HasPrefix(targetPath[0], "t=") {
// http://ID.example/t=TOKEN/PATH...
@@
-334,11
+342,6
@@
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
tokens = append(reqTokens, h.Config.AnonymousTokens...)
}
tokens = append(reqTokens, h.Config.AnonymousTokens...)
}
- if useSiteFS {
- h.serveSiteFS(w, r, tokens, credentialsOK)
- return
- }
-
if len(targetPath) > 0 && targetPath[0] == "_" {
// If a collection has a directory called "t=foo" or
// "_", it can be served at
if len(targetPath) > 0 && targetPath[0] == "_" {
// If a collection has a directory called "t=foo" or
// "_", it can be served at
@@
-416,6
+419,7
@@
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
statusCode, statusText = http.StatusInternalServerError, err.Error()
return
}
statusCode, statusText = http.StatusInternalServerError, err.Error()
return
}
+ kc.RequestID = r.Header.Get("X-Request-Id")
var basename string
if len(targetPath) > 0 {
var basename string
if len(targetPath) > 0 {
@@
-423,11
+427,11
@@
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
}
applyContentDispositionHdr(w, r, basename, attachment)
}
applyContentDispositionHdr(w, r, basename, attachment)
- client := &arvados.Client{
+ client :=
(
&arvados.Client{
APIHost: arv.ApiServer,
AuthToken: arv.ApiToken,
Insecure: arv.ApiInsecure,
APIHost: arv.ApiServer,
AuthToken: arv.ApiToken,
Insecure: arv.ApiInsecure,
- }
+ }
).WithRequestID(r.Header.Get("X-Request-Id"))
fs, err := collection.FileSystem(client, kc)
if err != nil {
fs, err := collection.FileSystem(client, kc)
if err != nil {
@@
-505,7
+509,7
@@
func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
}
}
}
}
-func (h *handler) serveSiteFS(w http.ResponseWriter, r *http.Request, tokens []string, credentialsOK bool) {
+func (h *handler) serveSiteFS(w http.ResponseWriter, r *http.Request, tokens []string, credentialsOK
, attachment
bool) {
if len(tokens) == 0 {
w.Header().Add("WWW-Authenticate", "Basic realm=\"collections\"")
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
if len(tokens) == 0 {
w.Header().Add("WWW-Authenticate", "Basic realm=\"collections\"")
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
@@
-528,11
+532,12
@@
func (h *handler) serveSiteFS(w http.ResponseWriter, r *http.Request, tokens []s
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- client := &arvados.Client{
+ kc.RequestID = r.Header.Get("X-Request-Id")
+ client := (&arvados.Client{
APIHost: arv.ApiServer,
AuthToken: arv.ApiToken,
Insecure: arv.ApiInsecure,
APIHost: arv.ApiServer,
AuthToken: arv.ApiToken,
Insecure: arv.ApiInsecure,
- }
+ }
).WithRequestID(r.Header.Get("X-Request-Id"))
fs := client.SiteFileSystem(kc)
f, err := fs.Open(r.URL.Path)
if os.IsNotExist(err) {
fs := client.SiteFileSystem(kc)
f, err := fs.Open(r.URL.Path)
if os.IsNotExist(err) {
@@
-551,6
+556,10
@@
func (h *handler) serveSiteFS(w http.ResponseWriter, r *http.Request, tokens []s
}
return
}
}
return
}
+ if r.Method == "GET" {
+ _, basename := filepath.Split(r.URL.Path)
+ applyContentDispositionHdr(w, r, basename, attachment)
+ }
wh := webdav.Handler{
Prefix: "/",
FileSystem: &webdavFS{
wh := webdav.Handler{
Prefix: "/",
FileSystem: &webdavFS{
@@
-610,9
+619,9
@@
the entire directory tree with wget, try:</P>
<UL>
{{range .Files}}
{{if .IsDir }}
<UL>
{{range .Files}}
{{if .IsDir }}
- <LI>{{" " | printf "%15s " | nbsp}}<A href="{{.Name}}/">{{.Name}}/</A></LI>
+ <LI>{{" " | printf "%15s " | nbsp}}<A href="{{
print "./"
.Name}}/">{{.Name}}/</A></LI>
{{else}}
{{else}}
- <LI>{{.Size | printf "%15d " | nbsp}}<A href="{{.Name}}">{{.Name}}</A></LI>
+ <LI>{{.Size | printf "%15d " | nbsp}}<A href="{{
print "./"
.Name}}">{{.Name}}</A></LI>
{{end}}
{{end}}
</UL>
{{end}}
{{end}}
</UL>