OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.42k stars 1.92k forks source link

RequestTemplate.path() doesn't return a stable value in RequestInterceptor.apply when retry #1687

Closed ganpanlin closed 1 year ago

ganpanlin commented 2 years ago

first time to run, RequestTemplate.path() resturns a value without "target"

public String path() {
 StringBuilder path = new StringBuilder();
    if (this.target != null) {    //this.target  is null
      path.append(this.target);
    }
}

it returns like '/api/v4/spot/accounts'

when retry triggered:

public String path() {
 StringBuilder path = new StringBuilder();
    if (this.target != null) {    //this.target  is not null
      path.append(this.target);
    }
}

it returns like 'https://api.gateio.ws/api/v4/spot/accounts'

velo commented 2 years ago

Ow dear, this is another side effect of RequestTemplate been mutable

HardCodedTarget does change the path if path doesn't contain http on it....
Oddly enough, if you are using a feign client to talk with a ftp:// it will include the url over, and over, and over again...

the only solution I could think to have a MORE consistent result, would be to expose a new method called relativePath() and that would return this.uriTemplate.toString()

Lemme know if that would solve your issue, and push a PR for this change

ganpanlin commented 2 years ago

thank you,the value of this.uriTemplate.toString() is what i need

kdavisk6 commented 1 year ago

Looks like you got what you needed. 👍🏻