|
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 ch.boye.httpclientandroidlib; |
|
29 |
|
30 import java.util.Locale; |
|
31 |
|
32 /** |
|
33 * After receiving and interpreting a request message, a server responds |
|
34 * with an HTTP response message. |
|
35 * <pre> |
|
36 * Response = Status-Line |
|
37 * *(( general-header |
|
38 * | response-header |
|
39 * | entity-header ) CRLF) |
|
40 * CRLF |
|
41 * [ message-body ] |
|
42 * </pre> |
|
43 * |
|
44 * @since 4.0 |
|
45 */ |
|
46 public interface HttpResponse extends HttpMessage { |
|
47 |
|
48 /** |
|
49 * Obtains the status line of this response. |
|
50 * The status line can be set using one of the |
|
51 * {@link #setStatusLine setStatusLine} methods, |
|
52 * or it can be initialized in a constructor. |
|
53 * |
|
54 * @return the status line, or <code>null</code> if not yet set |
|
55 */ |
|
56 StatusLine getStatusLine(); |
|
57 |
|
58 /** |
|
59 * Sets the status line of this response. |
|
60 * |
|
61 * @param statusline the status line of this response |
|
62 */ |
|
63 void setStatusLine(StatusLine statusline); |
|
64 |
|
65 /** |
|
66 * Sets the status line of this response. |
|
67 * The reason phrase will be determined based on the current |
|
68 * {@link #getLocale locale}. |
|
69 * |
|
70 * @param ver the HTTP version |
|
71 * @param code the status code |
|
72 */ |
|
73 void setStatusLine(ProtocolVersion ver, int code); |
|
74 |
|
75 /** |
|
76 * Sets the status line of this response with a reason phrase. |
|
77 * |
|
78 * @param ver the HTTP version |
|
79 * @param code the status code |
|
80 * @param reason the reason phrase, or <code>null</code> to omit |
|
81 */ |
|
82 void setStatusLine(ProtocolVersion ver, int code, String reason); |
|
83 |
|
84 /** |
|
85 * Updates the status line of this response with a new status code. |
|
86 * The status line can only be updated if it is available. It must |
|
87 * have been set either explicitly or in a constructor. |
|
88 * <br/> |
|
89 * The reason phrase will be updated according to the new status code, |
|
90 * based on the current {@link #getLocale locale}. It can be set |
|
91 * explicitly using {@link #setReasonPhrase setReasonPhrase}. |
|
92 * |
|
93 * @param code the HTTP status code. |
|
94 * |
|
95 * @throws IllegalStateException |
|
96 * if the status line has not be set |
|
97 * |
|
98 * @see HttpStatus |
|
99 * @see #setStatusLine(StatusLine) |
|
100 * @see #setStatusLine(ProtocolVersion,int) |
|
101 */ |
|
102 void setStatusCode(int code) |
|
103 throws IllegalStateException; |
|
104 |
|
105 /** |
|
106 * Updates the status line of this response with a new reason phrase. |
|
107 * The status line can only be updated if it is available. It must |
|
108 * have been set either explicitly or in a constructor. |
|
109 * |
|
110 * @param reason the new reason phrase as a single-line string, or |
|
111 * <code>null</code> to unset the reason phrase |
|
112 * |
|
113 * @throws IllegalStateException |
|
114 * if the status line has not be set |
|
115 * |
|
116 * @see #setStatusLine(StatusLine) |
|
117 * @see #setStatusLine(ProtocolVersion,int) |
|
118 */ |
|
119 void setReasonPhrase(String reason) |
|
120 throws IllegalStateException; |
|
121 |
|
122 /** |
|
123 * Obtains the message entity of this response, if any. |
|
124 * The entity is provided by calling {@link #setEntity setEntity}. |
|
125 * |
|
126 * @return the response entity, or |
|
127 * <code>null</code> if there is none |
|
128 */ |
|
129 HttpEntity getEntity(); |
|
130 |
|
131 /** |
|
132 * Associates a response entity with this response. |
|
133 * |
|
134 * @param entity the entity to associate with this response, or |
|
135 * <code>null</code> to unset |
|
136 */ |
|
137 void setEntity(HttpEntity entity); |
|
138 |
|
139 /** |
|
140 * Obtains the locale of this response. |
|
141 * The locale is used to determine the reason phrase |
|
142 * for the {@link #setStatusCode status code}. |
|
143 * It can be changed using {@link #setLocale setLocale}. |
|
144 * |
|
145 * @return the locale of this response, never <code>null</code> |
|
146 */ |
|
147 Locale getLocale(); |
|
148 |
|
149 /** |
|
150 * Changes the locale of this response. |
|
151 * If there is a status line, it's reason phrase will be updated |
|
152 * according to the status code and new locale. |
|
153 * |
|
154 * @param loc the new locale |
|
155 * |
|
156 * @see #getLocale getLocale |
|
157 * @see #setStatusCode setStatusCode |
|
158 */ |
|
159 void setLocale(Locale loc); |
|
160 } |