1 package com.bradmcevoy.http;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Date;
6 import java.util.List;
7 import java.util.Map;
8
9 public interface Request {
10
11
12 enum Depth {
13
14 ZERO,
15 ONE,
16 INFINITY
17 }
18
19 enum CacheControlRequest {
20
21 NO_CACHE( "no-cache" ),
22 NO_STORE( "no-store" ),
23 MAX_AGE( "max-age" ), // =delta-seconds
24 MAX_STALE( "max-stale" ), // =delta-seconds
25 MIN_FRESH( "min-fresh" ), // =delta-seconds
26 NO_TRANSFORM( "no-transform" ),
27 ONLY_IF_CACHED( "only-if-cached" ),
28 CACHE_EXT( "cache-extension" );
29 public String code;
30
31 CacheControlRequest( String code ) {
32 this.code = code;
33 }
34 }
35
36 enum Header {
37
38 CACHE_CONTROL( "Cache-Control" ),
39 WWW_AUTHENTICATE( "WWW-Authenticate" ),
40 IF( "If" ),
41 IF_MODIFIED( "If-Modified-Since" ),
42 IF_NOT_MODIFIED( "If-Unmodified-Since" ),
43 CONTENT_LENGTH( "Content-Length" ),
44 CONTENT_TYPE( "Content-Type" ),
45 CONTENT_RANGE( "Content-Range" ),
46 DEPTH( "Depth" ),
47 HOST( "Host" ),
48 DESTINATION( "Destination" ),
49 REFERER( "Referer" ),
50 ACCEPT( "Accept" ),
51 RANGE( "Range" ),
52 ACCEPT_ENCODING( "Accept-Encoding" ),
53 TIMEOUT( "Timeout" ),
54 LOCK_TOKEN( "Lock-Token" ),
55 EXPECT( "Expect" ),
56 OVERWRITE( "Overwrite" ),
57 USER_AGENT( "User-Agent" ),
58 /**
59 * For compatibility with macOS finder from 10.5.3
60 */
61 X_EXPECTED_ENTITY_LENGTH( "X-Expected-Entity-Length" ),
62 AUTHORIZATION( "Authorization" );
63 public String code;
64
65 Header( String code ) {
66 this.code = code;
67 }
68 }
69
70 enum Method {
71
72 HEAD( "HEAD", false ),
73 PROPFIND( "PROPFIND", false ),
74 PROPPATCH( "PROPPATCH", true ),
75 MKCOL( "MKCOL", true ),
76 MKCALENDAR( "MKCALENDAR", true ),
77 COPY( "COPY", true ),
78 MOVE( "MOVE", true ),
79 LOCK( "LOCK", true ),
80 UNLOCK( "UNLOCK", true ),
81 DELETE( "DELETE", true ),
82 GET( "GET", false ),
83 OPTIONS( "OPTIONS", false ),
84 POST( "POST", true ),
85 PUT( "PUT", true ),
86 TRACE( "TRACE", false ),
87 ACL( "ACL", true ),
88 CONNECT( "CONNECT", true ),
89 REPORT( "REPORT", false );
90 public String code;
91 public boolean isWrite;
92
93 Method( String code, boolean isWrite ) {
94 this.code = code;
95 this.isWrite = isWrite;
96 }
97 };
98
99 Map<String, String> getHeaders();
100
101 String getFromAddress();
102
103 String getLockTokenHeader();
104
105 String getRequestHeader( Request.Header header );
106
107 Method getMethod();
108
109 Auth getAuthorization();
110
111 /**
112 * Maybe called by the milton framework after successful non-http authentication
113 *
114 * @param auth - the new auth object
115 */
116 void setAuthorization(Auth auth);
117
118 String getRefererHeader();
119
120 String getTimeoutHeader();
121
122 String getIfHeader();
123
124 Date getIfModifiedHeader();
125
126 int getDepthHeader();
127
128 /** Return the complete URL, including protocol, host and port (if specified)
129 * and path
130 */
131 String getAbsoluteUrl();
132
133 /** Return the path portion of the url. This is everything following the
134 * host and port. Will always begin with a leading slash
135 */
136 String getAbsolutePath();
137
138 String getHostHeader();
139
140 String getDestinationHeader();
141
142 String getExpectHeader();
143
144 InputStream getInputStream() throws IOException;
145
146 void parseRequestParameters( Map<String, String> params, Map<String, FileItem> files ) throws RequestParseException;
147
148 String getContentTypeHeader();
149
150 Long getContentLengthHeader();
151
152 String getAcceptHeader();
153
154 String getAcceptEncodingHeader();
155
156 /**
157 *
158 * @return a range header, for partial gets
159 */
160 String getRangeHeader();
161
162
163 /**
164 * Used for partial PUTs
165 *
166 * @return
167 */
168 String getContentRangeHeader();
169
170 /**
171 * Used for MOVE and COPY methods. If true it indicates that any existing resource
172 * should be deleted before the move.
173 *
174 * @return - null if no value, true indicates that any existing resource
175 * should be deleted
176 */
177 Boolean getOverwriteHeader();
178
179 /**
180 *
181 * @return - the user agent header field
182 */
183 String getUserAgentHeader();
184
185 /**
186 * Return a writable map of arbitrary values to be associated with the request
187 *
188 * @return a writable map of arbitrary values to be associated with the request
189 */
190 Map<String,Object> getAttributes();
191
192 /**
193 * Note to implementors: the parameters will be created by the core handler
194 * classes and added to the attributes map. If you're extending AbstractRequest
195 * this method will already be implemented for you by returning that attribute
196 *
197 * If you are not extending AbstractRequest you should implement this as:
198 *
199 * return attributes.get( "_params");
200 *
201 * @return - map of querystring or POST parameters, keyed by name
202 */
203 Map<String, String> getParams();
204
205 /**
206 * Note to implementors: the parameters will be created by the core handler
207 * classes and added to the attributes map. If you're extending AbstractRequest
208 * this method will already be implemented for you by returning that attribute
209 *
210 * If you are not extending AbstractRequest you should return implement this as: return attributes.get( "_files");
211 *
212 * @return - a map of files from an upload request, keyed by file name
213 */
214 Map<String, FileItem> getFiles();
215
216
217
218 /**
219 * This is used to acquire a cookie using the name of that cookie.
220 * If the cookie exists within the HTTP header then it is returned
221 * as a <code>Cookie</code> object. Otherwise this method will
222 * return null. Each cookie object will contain the name, value
223 * and path of the cookie as well as the optional domain part.
224 *
225 * @param name this is the name of the cookie object to acquire
226 *
227 * @return this returns a cookie object from the header or null
228 */
229 Cookie getCookie(String name);
230
231 /**
232 * This is used to acquire all cookies that were sent in the header.
233 * If any cookies exists within the HTTP header they are returned
234 * as <code>Cookie</code> objects. Otherwise this method will an
235 * empty list. Each cookie object will contain the name, value and
236 * path of the cookie as well as the optional domain part.
237 *
238 * @return this returns all cookie objects from the HTTP header
239 */
240 List<Cookie> getCookies();
241
242 /**
243 * Returns the IP of the remote client
244 *
245 * @return
246 */
247 String getRemoteAddr();
248 }