org.springframework.http.client.StatusClientHttpResponse Maven / Gradle / Ivy
package org.springframework.http.client;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.util.StreamUtils;
public final class StatusClientHttpResponse implements ClientHttpResponse {
private final HttpStatus status;
private final HttpHeaders headers;
private final InputStream body;
public StatusClientHttpResponse(HttpStatus status) {
this(status, HttpEntity.EMPTY.getHeaders());
}
public StatusClientHttpResponse(HttpStatus status, HttpHeaders headers) {
this(status, headers, StreamUtils.nonClosing(StreamUtils.emptyInput()));
}
public StatusClientHttpResponse(HttpStatus status, HttpHeaders headers, InputStream body) {
this.status = status;
this.headers = headers;
this.body = body;
}
@Override
public HttpHeaders getHeaders() {
return this.headers;
}
@Override
public InputStream getBody() throws IOException {
return this.body;
}
@Override
public HttpStatus getStatusCode() throws IOException {
return this.status;
}
@Override
public int getRawStatusCode() throws IOException {
return this.status.value();
}
@Override
public String getStatusText() throws IOException {
return this.status.getReasonPhrase();
}
@Override
public void close() {
try (InputStream inputStream = this.body) {
}
catch (IOException e) {
// ignore
}
}
}