Introduce request attributes in RestClient
This commit introduces request attributes in the RestClient and underlying infrastructure (i.e. HttpRequest). Closes gh-32027
This commit is contained in:
@@ -18,6 +18,8 @@ package org.springframework.mock.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
@@ -46,6 +48,9 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
|
||||
|
||||
private boolean executed = false;
|
||||
|
||||
@Nullable
|
||||
Map<String, Object> attributes;
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@code MockClientHttpRequest} with {@link HttpMethod#GET GET} as
|
||||
@@ -115,6 +120,16 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
|
||||
return this.executed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAttributes() {
|
||||
Map<String, Object> attributes = this.attributes;
|
||||
if (attributes == null) {
|
||||
attributes = new ConcurrentHashMap<>();
|
||||
this.attributes = attributes;
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link #isExecuted() executed} flag to {@code true} and return the
|
||||
* configured {@link #setResponse(ClientHttpResponse) response}.
|
||||
|
||||
Reference in New Issue
Block a user