View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http;
29  
30  import java.util.Locale;
31  
32  import org.apache.http.impl.DefaultHttpRequestFactory;
33  
34  /**
35   * After receiving and interpreting a request message, a server responds
36   * with an HTTP response message.
37   * <pre>
38   *     Response      = Status-Line
39   *                     *(( general-header
40   *                      | response-header
41   *                      | entity-header ) CRLF)
42   *                     CRLF
43   *                     [ message-body ]
44   * </pre>
45   *
46   * @since 4.0
47   */
48  public interface HttpResponse extends HttpMessage {
49  
50      /**
51       * Obtains the status line of this response.
52       * The status line can be set using one of the
53       * {@link #setStatusLine setStatusLine} methods,
54       * or it can be initialized in a constructor.
55       *
56       * @return  the status line, or <code>null</code> if not yet set
57       */
58      StatusLine getStatusLine();
59  
60      /**
61       * Sets the status line of this response.
62       *
63       * @param statusline the status line of this response
64       */
65      void setStatusLine(StatusLine statusline);
66  
67      /**
68       * Sets the status line of this response.
69       * The reason phrase will be determined based on the current
70       * {@link #getLocale locale}.
71       *
72       * @param ver       the HTTP version
73       * @param code      the status code
74       */
75      void setStatusLine(ProtocolVersion ver, int code);
76  
77      /**
78       * Sets the status line of this response with a reason phrase.
79       *
80       * @param ver       the HTTP version
81       * @param code      the status code
82       * @param reason    the reason phrase, or <code>null</code> to omit
83       */
84      void setStatusLine(ProtocolVersion ver, int code, String reason);
85  
86      /**
87       * Updates the status line of this response with a new status code.
88       * The status line can only be updated if it is available. It must
89       * have been set either explicitly or in a constructor.
90       * <br/>
91       * The reason phrase will be updated according to the new status code,
92       * based on the current {@link #getLocale locale}. It can be set
93       * explicitly using {@link #setReasonPhrase setReasonPhrase}.
94       *
95       * @param code the HTTP status code.
96       *
97       * @throws IllegalStateException
98       *          if the status line has not be set
99       *
100      * @see HttpStatus
101      * @see #setStatusLine(StatusLine)
102      * @see #setStatusLine(ProtocolVersion,int)
103      */
104     void setStatusCode(int code)
105         throws IllegalStateException;
106 
107     /**
108      * Updates the status line of this response with a new reason phrase.
109      * The status line can only be updated if it is available. It must
110      * have been set either explicitly or in a constructor.
111      *
112      * @param reason    the new reason phrase as a single-line string, or
113      *                  <code>null</code> to unset the reason phrase
114      *
115      * @throws IllegalStateException
116      *          if the status line has not be set
117      *
118      * @see #setStatusLine(StatusLine)
119      * @see #setStatusLine(ProtocolVersion,int)
120      */
121     void setReasonPhrase(String reason)
122         throws IllegalStateException;
123 
124     /**
125      * Obtains the message entity of this response, if any.
126      * The entity is provided by calling {@link #setEntity setEntity}.
127      *
128      * @return  the response entity, or
129      *          <code>null</code> if there is none
130      */
131     HttpEntity getEntity();
132 
133     /**
134      * Associates a response entity with this response.
135      * <p/>
136      * Please note that if an entity has already been set for this response and it depends on
137      * an input stream ({@link HttpEntity#isStreaming()} returns <code>true</code>),
138      * it must be fully consumed in order to ensure release of resources.
139      *
140      * @param entity    the entity to associate with this response, or
141      *                  <code>null</code> to unset
142      *
143      * @see HttpEntity#isStreaming()
144      * @see org.apache.http.util.EntityUtils#updateEntity(HttpResponse, HttpEntity)
145      */
146     void setEntity(HttpEntity entity);
147 
148     /**
149      * Obtains the locale of this response.
150      * The locale is used to determine the reason phrase
151      * for the {@link #setStatusCode status code}.
152      * It can be changed using {@link #setLocale setLocale}.
153      *
154      * @return  the locale of this response, never <code>null</code>
155      *
156      * @deprecated (4.3) use {@link DefaultHttpRequestFactory}
157      */
158     @Deprecated
159     Locale getLocale();
160 
161     /**
162      * Changes the locale of this response.
163      * If there is a status line, it's reason phrase will be updated
164      * according to the status code and new locale.
165      *
166      * @param loc       the new locale
167      *
168      * @deprecated (4.3) use {@link DefaultHttpRequestFactory}
169      */
170     @Deprecated
171     void setLocale(Locale loc);
172 
173 }