mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
[swarm] Verify if a GET request is to the root document of a swarm site and make sure it has a trailing slash. If it does not, use HTTP Found status for adding it through redirecting.
This commit is contained in:
parent
4051be278b
commit
260635a379
1 changed files with 6 additions and 3 deletions
|
|
@ -25,6 +25,7 @@ var (
|
||||||
// accepted protocols: bzz (traditional), bzzi (immutable) and bzzr (raw)
|
// accepted protocols: bzz (traditional), bzzi (immutable) and bzzr (raw)
|
||||||
bzzPrefix = regexp.MustCompile("^/+bzz[ir]?:/+")
|
bzzPrefix = regexp.MustCompile("^/+bzz[ir]?:/+")
|
||||||
trailingSlashes = regexp.MustCompile("/+$")
|
trailingSlashes = regexp.MustCompile("/+$")
|
||||||
|
rootDocumentUri = regexp.MustCompile("^/+bzz[i]?:/+[^/]+$")
|
||||||
// forever = func() time.Time { return time.Unix(0, 0) }
|
// forever = func() time.Time { return time.Unix(0, 0) }
|
||||||
forever = time.Now
|
forever = time.Now
|
||||||
)
|
)
|
||||||
|
|
@ -181,9 +182,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
|
||||||
|
|
||||||
// retrieve path via manifest
|
// retrieve path via manifest
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
glog.V(logger.Debug).Infof("[BZZ] Swarm: Structured GET request '%s' received.", uri)
|
glog.V(logger.Debug).Infof("[BZZ] Swarm: Structured GET request '%s' received.", uri)
|
||||||
|
// add trailing slash, if missing
|
||||||
|
if rootDocumentUri.MatchString(uri) {
|
||||||
|
http.Redirect(w, r, path+"/", http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
reader, mimeType, status, err := a.Get(path, nameresolver)
|
reader, mimeType, status, err := a.Get(path, nameresolver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(api.ErrResolve); ok {
|
if _, ok := err.(api.ErrResolve); ok {
|
||||||
|
|
@ -196,7 +200,6 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
|
||||||
http.Error(w, err.Error(), status)
|
http.Error(w, err.Error(), status)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// set mime type and status headers
|
// set mime type and status headers
|
||||||
w.Header().Set("Content-Type", mimeType)
|
w.Header().Set("Content-Type", mimeType)
|
||||||
if status > 0 {
|
if status > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue