001/*
002 * Copyright 2002-2020 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 *
028 * <p>Obtained via an invocation of {@link ClientHttpRequest#execute()}.
029 *
030 * <p>A {@code ClientHttpResponse} must be {@linkplain #close() closed},
031 * typically in a {@code finally} block.
032 *
033 * @author Arjen Poutsma
034 * @since 3.0
035 */
036public interface ClientHttpResponse extends HttpInputMessage, Closeable {
037
038        /**
039         * Get the HTTP status code as an {@link HttpStatus} enum value.
040         * <p>For status codes not supported by {@code HttpStatus}, use
041         * {@link #getRawStatusCode()} instead.
042         * @return the HTTP status as an HttpStatus enum value (never {@code null})
043         * @throws IOException in case of I/O errors
044         * @throws IllegalArgumentException in case of an unknown HTTP status code
045         * @since #getRawStatusCode()
046         * @see HttpStatus#valueOf(int)
047         */
048        HttpStatus getStatusCode() throws IOException;
049
050        /**
051         * Get the HTTP status code (potentially non-standard and not
052         * resolvable through the {@link HttpStatus} enum) as an integer.
053         * @return the HTTP status as an integer value
054         * @throws IOException in case of I/O errors
055         * @since 3.1.1
056         * @see #getStatusCode()
057         * @see HttpStatus#resolve(int)
058         */
059        int getRawStatusCode() throws IOException;
060
061        /**
062         * Get the HTTP status text of the response.
063         * @return the HTTP status text
064         * @throws IOException in case of I/O errors
065         */
066        String getStatusText() throws IOException;
067
068        /**
069         * Close this response, freeing any resources created.
070         */
071        @Override
072        void close();
073
074}