top.jfunc.http.response.BaseClientHttpResponse Maven / Gradle / Ivy
package top.jfunc.http.response;
import top.jfunc.http.component.HeaderExtractor;
import top.jfunc.http.component.StreamExtractor;
import top.jfunc.http.request.HttpRequest;
import top.jfunc.common.utils.MultiValueMap;
import java.io.IOException;
import java.io.InputStream;
/**
* RR 代表能从中获取header、InputStream的响应
* @author xiongshiyan
*/
public abstract class BaseClientHttpResponse implements ClientHttpResponse {
private StreamExtractor responseStreamExtractor;
private HeaderExtractor responseHeaderExtractor;
protected RR response;
protected HttpRequest httpRequest;
protected MultiValueMap headers;
protected InputStream responseStream;
public BaseClientHttpResponse(RR response, HttpRequest httpRequest, StreamExtractor streamExtractor, HeaderExtractor headerExtractor) {
this.response = response;
this.httpRequest = httpRequest;
setResponseStreamExtractor(streamExtractor);
setResponseHeaderExtractor(headerExtractor);
}
@Override
public MultiValueMap getHeaders() throws IOException {
if(null == this.headers){
this.headers = getResponseHeaderExtractor().extract(this.response, this.httpRequest);
}
return this.headers;
}
@Override
public InputStream getBody() throws IOException {
return this.responseStream = getResponseStreamExtractor().extract(this.response, this.httpRequest);
}
public StreamExtractor getResponseStreamExtractor() {
return responseStreamExtractor;
}
public void setResponseStreamExtractor(StreamExtractor responseStreamExtractor) {
this.responseStreamExtractor = responseStreamExtractor;
}
public HeaderExtractor getResponseHeaderExtractor() {
return responseHeaderExtractor;
}
public void setResponseHeaderExtractor(HeaderExtractor responseHeaderExtractor) {
this.responseHeaderExtractor = responseHeaderExtractor;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy