In case of conflict during registration, the old registration is now recovered

This commit is contained in:
Till Klocke 2016-06-06 14:13:45 +02:00
parent 30a7a8e882
commit 599eb9a739

View file

@ -167,15 +167,29 @@ func (c *Client) Register() (*RegistrationResource, error) {
} }
var serverReg Registration var serverReg Registration
var regURI string
hdr, err := postJSON(c.jws, c.directory.NewRegURL, regMsg, &serverReg) hdr, err := postJSON(c.jws, c.directory.NewRegURL, regMsg, &serverReg)
if err != nil { if err != nil {
return nil, err remoteErr, ok := err.(RemoteError)
if ok && remoteErr.StatusCode == 409 {
regURI = hdr.Get("Location")
regMsg.Resource = "reg"
if hdr, err = postJSON(c.jws, regURI, regMsg, &serverReg); err != nil {
return nil, err
}
} else {
return nil, err
}
} }
reg := &RegistrationResource{Body: serverReg} reg := &RegistrationResource{Body: serverReg}
links := parseLinks(hdr["Link"]) links := parseLinks(hdr["Link"])
reg.URI = hdr.Get("Location")
if regURI == "" {
regURI = hdr.Get("Location")
}
reg.URI = regURI
if links["terms-of-service"] != "" { if links["terms-of-service"] != "" {
reg.TosURL = links["terms-of-service"] reg.TosURL = links["terms-of-service"]
} }