001package ca.uhn.fhir.rest.client.api;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2017 University Health Network
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 * http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import java.io.IOException;
024import java.io.InputStream;
025import java.io.Reader;
026import java.util.List;
027import java.util.Map;
028
029/**
030 * An interface around the HTTP Response.
031 */
032public interface IHttpResponse {
033
034        /**
035         * @deprecated This method was deprecated in HAPI FHIR 2.2 because its name has a typo. Use {@link #bufferEntity()} instead.
036         */
037        @Deprecated
038        void bufferEntitity() throws IOException;
039
040        /**
041         * Buffer the message entity data.
042         * <p>
043         * In case the message entity is backed by an unconsumed entity input stream,
044         * all the bytes of the original entity input stream are read and stored in a
045         * local buffer. The original entity input stream is consumed.
046         * </p>
047         * <p>
048         * In case the response entity instance is not backed by an unconsumed input stream
049         * an invocation of {@code bufferEntity} method is ignored and the method returns.
050         * </p>
051         * <p>
052         * This operation is idempotent, i.e. it can be invoked multiple times with
053         * the same effect which also means that calling the {@code bufferEntity()}
054         * method on an already buffered (and thus closed) message instance is legal
055         * and has no further effect.
056         * </p>
057         * <p>
058         * Buffering the message entity data allows for multiple invocations of
059         * {@code readEntity(...)} methods on the response instance.
060         * 
061         * @since 2.2
062         */
063        void bufferEntity() throws IOException;
064
065        /**
066         * Close the response
067         */
068        public void close();
069
070        /**
071         * Returna reader for the response entity
072         */
073        public Reader createReader() throws IOException;
074
075        /**
076         * Get map of the response headers and corresponding string values.
077         * 
078         * @return response headers as a map header keys and they values.
079         */
080        public Map<String, List<String>> getAllHeaders();
081
082        /**
083         * Return all headers in the response with the given type 
084         */
085        public List<String> getHeaders(String theName);
086
087        /**
088         * Extracts {@code Content-Type} value from the response exactly as
089         * specified by the {@code Content-Type} header. Returns {@code null}
090         * if not specified.
091         */
092        public String getMimeType();
093
094        /**
095         * @return the native response, depending on the client library used
096         */
097        Object getResponse();
098
099        /**
100         * Get the status code associated with the response.
101         * 
102         * @return the response status code.
103         */
104        public int getStatus();
105
106        /**
107         * Get the response status information reason phrase associated with the response.
108         * 
109         * @return the reason phrase.
110         */
111        public String getStatusInfo();
112
113        /**
114         * Read the message entity input stream as an InputStream.
115         */
116        public InputStream readEntity() throws IOException;
117
118}