ETag, Content-Type, Metalink, compression -- everything should be
applicable in WebDAV-enabled directories too.
// Highly-customizable HTTP, HTTP/2, HTTPS server
package godlighty
// Highly-customizable HTTP, HTTP/2, HTTPS server
package godlighty
-const Version = "godlighty/0.2.0"
+const Version = "godlighty/0.3.0"
+ w.Header().Set("Server", Version)
if cfg == nil {
notFound()
return
if cfg == nil {
notFound()
return
- if cfg.WebDAV && (r.Method == http.MethodHead ||
+ pthOrig := path.Clean(path.Join(cfg.Root, r.URL.Path))
+ pth := pthOrig
+ fi, err := os.Stat(pth)
+ if err != nil {
+ notFound()
+ return
+ }
+
+ if cfg.WebDAV && (((r.Method == http.MethodHead) && fi.IsDir()) ||
r.Method == http.MethodOptions ||
r.Method == "PROPFIND") {
dav := webdav.Handler{
r.Method == http.MethodOptions ||
r.Method == "PROPFIND") {
dav := webdav.Handler{
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
var fd *os.File
var contentType string
var etag string
var fd *os.File
var contentType string
var etag string
- pthOrig := path.Clean(path.Join(cfg.Root, r.URL.Path))
- pth := pthOrig
-IndexLookup:
- fi, err := os.Stat(pth)
- if err != nil {
- notFound()
- return
- }
if fi.IsDir() {
if cfg.DirList {
entries, err := os.ReadDir(pth)
if fi.IsDir() {
if cfg.DirList {
entries, err := os.ReadDir(pth)
p := path.Join(pth, index)
if _, err := os.Stat(p); err == nil {
pth = p
p := path.Join(pth, index)
if _, err := os.Stat(p); err == nil {
pth = p
+ fi, err = os.Stat(pth)
+ if err != nil {
+ notFound()
+ return
+ }
+ goto IndexLookuped
contentTypeBase := strings.SplitN(contentType, ";", 2)[0]
w.Header().Set("Content-Type", contentType)
contentTypeBase := strings.SplitN(contentType, ";", 2)[0]
w.Header().Set("Content-Type", contentType)
- w.Header().Set("Server", Version)
if etag != "" {
w.Header().Set("ETag", etag)
}
if etag != "" {
w.Header().Set("ETag", etag)
}