diff options
author | holisticode <holistic.computing@gmail.com> | 2017-10-06 21:45:54 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-10-06 21:45:54 +0800 |
commit | 1ae0411d419d2178727048021f8dc09b6ccd1d82 (patch) | |
tree | e1958ecbcad5581d27c56afd5c03258309e19861 /swarm/api/manifest.go | |
parent | d54e3539d453c78e30d950706f6465743723a33c (diff) | |
download | dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.tar dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.tar.gz dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.tar.bz2 dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.tar.lz dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.tar.xz dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.tar.zst dexon-1ae0411d419d2178727048021f8dc09b6ccd1d82.zip |
swarm/api: fixed 404 handling on missing default entry (#15139)
Diffstat (limited to 'swarm/api/manifest.go')
-rw-r--r-- | swarm/api/manifest.go | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go index 90f287677..d3eced198 100644 --- a/swarm/api/manifest.go +++ b/swarm/api/manifest.go @@ -22,6 +22,8 @@ import ( "errors" "fmt" "io" + "net/http" + "strings" "sync" "time" @@ -422,25 +424,47 @@ func (self *manifestTrie) findPrefixOf(path string, quitC chan bool) (entry *man return self.entries[256], 0 } + //see if first char is in manifest entries b := byte(path[0]) entry = self.entries[b] if entry == nil { return self.entries[256], 0 } + epl := len(entry.Path) log.Trace(fmt.Sprintf("path = %v entry.Path = %v epl = %v", path, entry.Path, epl)) - if (len(path) >= epl) && (path[:epl] == entry.Path) { + if len(path) <= epl { + if entry.Path[:len(path)] == path { + if entry.ContentType == ManifestType { + entry.Status = http.StatusMultipleChoices + } + pos = len(path) + return + } + return nil, 0 + } + if path[:epl] == entry.Path { log.Trace(fmt.Sprintf("entry.ContentType = %v", entry.ContentType)) - if entry.ContentType == ManifestType { + //the subentry is a manifest, load subtrie + if entry.ContentType == ManifestType && (strings.Contains(entry.Path, path) || strings.Contains(path, entry.Path)) { err := self.loadSubTrie(entry, quitC) if err != nil { return nil, 0 } - entry, pos = entry.subtrie.findPrefixOf(path[epl:], quitC) - if entry != nil { + sub, pos := entry.subtrie.findPrefixOf(path[epl:], quitC) + if sub != nil { + entry = sub pos += epl + return sub, pos + } else if path == entry.Path { + entry.Status = http.StatusMultipleChoices } + } else { + //entry is not a manifest, return it + if path != entry.Path { + return nil, 0 + } pos = epl } } |