The Request class encapsulates a single HTTP request.
| 1318 | * The {@code Request} class encapsulates a single HTTP request. |
| 1319 | */ |
| 1320 | public class Request { |
| 1321 | |
| 1322 | protected String method; |
| 1323 | protected URI uri; |
| 1324 | protected URL baseURL; // cached value |
| 1325 | protected String version; |
| 1326 | protected Headers headers; |
| 1327 | protected InputStream body; |
| 1328 | protected Map<String, String> params; // cached value |
| 1329 | protected VirtualHost host; // cached value |
| 1330 | protected VirtualHost.ContextInfo context; // cached value |
| 1331 | |
| 1332 | /** |
| 1333 | * Constructs a Request from the data in the given input stream. |
| 1334 | * |
| 1335 | * @param in the input stream from which the request is read |
| 1336 | * @throws IOException if an error occurs |
| 1337 | */ |
| 1338 | public Request(InputStream in) throws IOException { |
| 1339 | readRequestLine(in); |
| 1340 | headers = readHeaders(in); |
| 1341 | // RFC2616#3.6 - if "chunked" is used, it must be the last one |
| 1342 | // RFC2616#4.4 - if non-identity Transfer-Encoding is present, |
| 1343 | // it must either include "chunked" or close the connection after |
| 1344 | // the body, and in any case ignore Content-Length. |
| 1345 | // if there is no such Transfer-Encoding, use Content-Length |
| 1346 | // if neither header exists, there is no body |
| 1347 | String header = headers.get("Transfer-Encoding"); |
| 1348 | if (header != null && !header.toLowerCase(Locale.US).equals("identity")) { |
| 1349 | if (Arrays.asList(splitElements(header, true)).contains("chunked")) |
| 1350 | body = new ChunkedInputStream(in, headers); |
| 1351 | else |
| 1352 | body = in; // body ends when connection closes |
| 1353 | } else { |
| 1354 | header = headers.get("Content-Length"); |
| 1355 | long len = header == null ? 0 : parseULong(header, 10); |
| 1356 | body = new LimitedInputStream(in, len, false); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | /** |
| 1361 | * Returns the request method. |
| 1362 | * |
| 1363 | * @return the request method |
| 1364 | */ |
| 1365 | public String getMethod() { return method; } |
| 1366 | |
| 1367 | /** |
| 1368 | * Returns the request URI. |
| 1369 | * |
| 1370 | * @return the request URI |
| 1371 | */ |
| 1372 | public URI getURI() { return uri; } |
| 1373 | |
| 1374 | /** |
| 1375 | * Returns the request version string. |
| 1376 | * |
| 1377 | * @return the request version string |
nothing calls this directly
no outgoing calls
no test coverage detected