001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.http.client; 018 019import java.io.Closeable; 020import java.io.IOException; 021 022import org.springframework.http.HttpInputMessage; 023import org.springframework.http.HttpStatus; 024 025/** 026 * Represents a client-side HTTP response. 027 * Obtained via an calling of the {@link ClientHttpRequest#execute()}. 028 * 029 * <p>A {@code ClientHttpResponse} must be {@linkplain #close() closed}, 030 * typically in a {@code finally} block. 031 * 032 * @author Arjen Poutsma 033 * @since 3.0 034 */ 035public interface ClientHttpResponse extends HttpInputMessage, Closeable { 036 037 /** 038 * Return the HTTP status code of the response. 039 * @return the HTTP status as an HttpStatus enum value 040 * @throws IOException in case of I/O errors 041 * @throws IllegalArgumentException in case of an unknown HTTP status code 042 * @see HttpStatus#valueOf(int) 043 */ 044 HttpStatus getStatusCode() throws IOException; 045 046 /** 047 * Return the HTTP status code (potentially non-standard and not 048 * resolvable through the {@link HttpStatus} enum) as an integer. 049 * @return the HTTP status as an integer 050 * @throws IOException in case of I/O errors 051 * @since 3.1.1 052 * @see #getStatusCode() 053 */ 054 int getRawStatusCode() throws IOException; 055 056 /** 057 * Return the HTTP status text of the response. 058 * @return the HTTP status text 059 * @throws IOException in case of I/O errors 060 */ 061 String getStatusText() throws IOException; 062 063 /** 064 * Close this response, freeing any resources created. 065 */ 066 @Override 067 void close(); 068 069}