forked from TrueCloudLab/lego
In case of conflict during registration, the old registration is now recovered
This commit is contained in:
parent
30a7a8e882
commit
599eb9a739
1 changed files with 16 additions and 2 deletions
|
@ -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"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue