examples/client: Handle relative redirects
This commit is contained in:
parent
38fe1f21dc
commit
f6be76f8b8
@ -82,8 +82,7 @@ func login(rw *gmi.ResponseWriter, req *gmi.Request) {
|
||||
sessions[fingerprint] = &session{
|
||||
username: username,
|
||||
}
|
||||
// TODO: Remove scheme and host once example client can handle relative redirects
|
||||
rw.WriteHeader(gmi.StatusRedirect, "gemini://localhost/login/password")
|
||||
rw.WriteHeader(gmi.StatusRedirect, "/login/password")
|
||||
}
|
||||
} else {
|
||||
rw.WriteHeader(gmi.StatusClientCertificateRequired, "Certificate required")
|
||||
@ -103,9 +102,8 @@ func loginPassword(rw *gmi.ResponseWriter, req *gmi.Request) {
|
||||
} else {
|
||||
expected := logins[session.username].password
|
||||
if password == expected {
|
||||
// TODO: Remove scheme and host once example client can handle relative redirects
|
||||
session.authorized = true
|
||||
rw.WriteHeader(gmi.StatusRedirect, "gemini://localhost/profile")
|
||||
rw.WriteHeader(gmi.StatusRedirect, "/profile")
|
||||
} else {
|
||||
rw.WriteHeader(gmi.StatusInput, "Wrong password. Please try again")
|
||||
}
|
||||
|
@ -64,12 +64,16 @@ func sendRequest(req *gmi.Request) error {
|
||||
fmt.Print(string(resp.Body))
|
||||
return nil
|
||||
case gmi.StatusClassRedirect:
|
||||
fmt.Println("Redirecting to ", resp.Meta)
|
||||
req, err := gmi.NewRequest(resp.Meta)
|
||||
fmt.Println("Redirecting to", resp.Meta)
|
||||
// Make the request to the same host
|
||||
red, err := gmi.NewProxyRequest(req.Host, resp.Meta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return sendRequest(req)
|
||||
// Handle relative redirects
|
||||
red.URL = req.URL.ResolveReference(red.URL)
|
||||
fmt.Println(red.URL, red.Host)
|
||||
return sendRequest(red)
|
||||
case gmi.StatusClassTemporaryFailure:
|
||||
return fmt.Errorf("Temporary failure: %s", resp.Meta)
|
||||
case gmi.StatusClassPermanentFailure:
|
||||
|
Loading…
Reference in New Issue
Block a user