mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
added support for /vid/keycookie/filename.txt format for HTTP GET
This commit is contained in:
parent
4c280bc317
commit
49cc81fdab
|
@ -176,7 +176,7 @@ func volumeStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func redirectHandler(w http.ResponseWriter, r *http.Request) {
|
func redirectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vid, _, _ := parseURLPath(r.URL.Path)
|
vid, _, _, _ := parseURLPath(r.URL.Path)
|
||||||
volumeId, err := storage.NewVolumeId(vid)
|
volumeId, err := storage.NewVolumeId(vid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug("parsing error:", err, r.URL.Path)
|
debug("parsing error:", err, r.URL.Path)
|
||||||
|
|
|
@ -112,7 +112,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
||||||
n := new(storage.Needle)
|
n := new(storage.Needle)
|
||||||
vid, fid, ext := parseURLPath(r.URL.Path)
|
vid, fid, filename, ext := parseURLPath(r.URL.Path)
|
||||||
volumeId, err := storage.NewVolumeId(vid)
|
volumeId, err := storage.NewVolumeId(vid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug("parsing error:", err, r.URL.Path)
|
debug("parsing error:", err, r.URL.Path)
|
||||||
|
@ -156,11 +156,11 @@ func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n.NameSize > 0 {
|
if n.NameSize > 0 && filename == "" {
|
||||||
fname := string(n.Name)
|
filename := string(n.Name)
|
||||||
dotIndex := strings.LastIndex(fname, ".")
|
dotIndex := strings.LastIndex(filename, ".")
|
||||||
if dotIndex > 0 {
|
if dotIndex > 0 {
|
||||||
ext = fname[dotIndex:]
|
ext = filename[dotIndex:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mtype := ""
|
mtype := ""
|
||||||
|
@ -173,8 +173,8 @@ func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool)
|
||||||
if mtype != "" {
|
if mtype != "" {
|
||||||
w.Header().Set("Content-Type", mtype)
|
w.Header().Set("Content-Type", mtype)
|
||||||
}
|
}
|
||||||
if n.NameSize > 0 {
|
if filename != "" {
|
||||||
w.Header().Set("Content-Disposition", "filename="+fileNameEscaper.Replace(string(n.Name)))
|
w.Header().Set("Content-Disposition", "filename="+fileNameEscaper.Replace(filename))
|
||||||
}
|
}
|
||||||
if ext != ".gz" {
|
if ext != ".gz" {
|
||||||
if n.IsGzipped() {
|
if n.IsGzipped() {
|
||||||
|
@ -200,7 +200,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
writeJsonQuiet(w, r, e)
|
writeJsonQuiet(w, r, e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vid, _, _ := parseURLPath(r.URL.Path)
|
vid, _, _, _ := parseURLPath(r.URL.Path)
|
||||||
volumeId, e := storage.NewVolumeId(vid)
|
volumeId, e := storage.NewVolumeId(vid)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
debug("NewVolumeId error:", e)
|
debug("NewVolumeId error:", e)
|
||||||
|
@ -229,7 +229,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
n := new(storage.Needle)
|
n := new(storage.Needle)
|
||||||
vid, fid, _ := parseURLPath(r.URL.Path)
|
vid, fid, _, _ := parseURLPath(r.URL.Path)
|
||||||
volumeId, _ := storage.NewVolumeId(vid)
|
volumeId, _ := storage.NewVolumeId(vid)
|
||||||
n.ParsePath(fid)
|
n.ParsePath(fid)
|
||||||
|
|
||||||
|
@ -264,23 +264,28 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
writeJsonQuiet(w, r, m)
|
writeJsonQuiet(w, r, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseURLPath(path string) (vid, fid, ext string) {
|
func parseURLPath(path string) (vid, fid, filename, ext string) {
|
||||||
|
if strings.Count(path, "/") == 3 {
|
||||||
sepIndex := strings.LastIndex(path, "/")
|
parts := strings.Split(path, "/")
|
||||||
commaIndex := strings.LastIndex(path[sepIndex:], ",")
|
vid, fid, filename = parts[1], parts[2], parts[3]
|
||||||
if commaIndex <= 0 {
|
ext = filename[strings.LastIndex(filename, "."):]
|
||||||
if "favicon.ico" != path[sepIndex+1:] {
|
} else {
|
||||||
log.Println("unknown file id", path[sepIndex+1:])
|
sepIndex := strings.LastIndex(path, "/")
|
||||||
|
commaIndex := strings.LastIndex(path[sepIndex:], ",")
|
||||||
|
if commaIndex <= 0 {
|
||||||
|
if "favicon.ico" != path[sepIndex+1:] {
|
||||||
|
log.Println("unknown file id", path[sepIndex+1:])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dotIndex := strings.LastIndex(path[sepIndex:], ".")
|
||||||
|
vid = path[sepIndex+1 : commaIndex]
|
||||||
|
fid = path[commaIndex+1:]
|
||||||
|
ext = ""
|
||||||
|
if dotIndex > 0 {
|
||||||
|
fid = path[commaIndex+1 : dotIndex]
|
||||||
|
ext = path[dotIndex:]
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
dotIndex := strings.LastIndex(path[sepIndex:], ".")
|
|
||||||
vid = path[sepIndex+1 : commaIndex]
|
|
||||||
fid = path[commaIndex+1:]
|
|
||||||
ext = ""
|
|
||||||
if dotIndex > 0 {
|
|
||||||
fid = path[commaIndex+1 : dotIndex]
|
|
||||||
ext = path[dotIndex:]
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue