feign icon indicating copy to clipboard operation
feign copied to clipboard

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

Open ganpanlin opened this issue 2 years ago • 2 comments

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'

ganpanlin avatar Jul 12 '22 15:07 ganpanlin

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

velo avatar Jul 12 '22 21:07 velo

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

ganpanlin avatar Jul 13 '22 03:07 ganpanlin

Looks like you got what you needed. 👍🏻

kdavisk6 avatar Oct 07 '22 20:10 kdavisk6