Skip to content

Commit c68d6c2

Browse files
committed
nice, passing tests with 301 redirects on /latest + /latest/meta-data
1 parent 9400073 commit c68d6c2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net/http"
67
"time"
78

@@ -47,6 +48,7 @@ func (app *App) serverSubRouter(sr *mux.Router) {
4748
sr.Handle("", appHandler(app.trailingSlashRedirect))
4849
sr.Handle("/", appHandler(app.secondLevelHandler))
4950
s := sr.PathPrefix("/meta-data").Subrouter()
51+
s.Handle("", appHandler(app.trailingSlashRedirect))
5052
s.Handle("/", appHandler(app.metaDataHandler))
5153
s.Handle("/instance-id", appHandler(app.instanceIDHandler))
5254
s.Handle("/local-hostname", appHandler(app.localHostnameHandler))
@@ -155,7 +157,12 @@ func (app *App) securityCredentialsHandler(w http.ResponseWriter, r *http.Reques
155157
}
156158

157159
func (app *App) trailingSlashRedirect(w http.ResponseWriter, r *http.Request) {
158-
w.Header().Set("Location", r.URL.String()+"/")
160+
location := ""
161+
if app.NoSchemeHostRedirects == false {
162+
location = "http://169.254.169.254"
163+
}
164+
location = fmt.Sprintf("%s%s/", location, r.URL.String())
165+
w.Header().Set("Location", location)
159166
w.WriteHeader(301)
160167
}
161168

0 commit comments

Comments
 (0)