The Response class encapsulates a single HTTP response.
| 1570 | * The {@code Response} class encapsulates a single HTTP response. |
| 1571 | */ |
| 1572 | public class Response implements Closeable { |
| 1573 | |
| 1574 | protected OutputStream out; // the underlying output stream |
| 1575 | protected OutputStream[] encoders = new OutputStream[4]; // chained encoder streams |
| 1576 | protected Headers headers; |
| 1577 | protected boolean discardBody; |
| 1578 | protected int state; // nothing sent, headers sent, or closed |
| 1579 | protected Request req; // request used in determining client capabilities |
| 1580 | |
| 1581 | /** |
| 1582 | * Constructs a Response whose output is written to the given stream. |
| 1583 | * |
| 1584 | * @param out the stream to which the response is written |
| 1585 | */ |
| 1586 | public Response(OutputStream out) { |
| 1587 | this.out = out; |
| 1588 | this.headers = new Headers(); |
| 1589 | } |
| 1590 | |
| 1591 | /** |
| 1592 | * Sets whether this response's body is discarded or sent. |
| 1593 | * |
| 1594 | * @param discardBody specifies whether the body is discarded or not |
| 1595 | */ |
| 1596 | public void setDiscardBody(boolean discardBody) { |
| 1597 | this.discardBody = discardBody; |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * Sets the request which is used in determining the capabilities |
| 1602 | * supported by the client (e.g. compression, encoding, etc.) |
| 1603 | * |
| 1604 | * @param req the request |
| 1605 | */ |
| 1606 | public void setClientCapabilities(Request req) { this.req = req; } |
| 1607 | |
| 1608 | /** |
| 1609 | * Returns the request headers collection. |
| 1610 | * |
| 1611 | * @return the request headers collection |
| 1612 | */ |
| 1613 | public Headers getHeaders() { return headers; } |
| 1614 | |
| 1615 | /** |
| 1616 | * Returns the underlying output stream to which the response is written. |
| 1617 | * Except for special cases, you should use {@link #getBody()} instead. |
| 1618 | * |
| 1619 | * @return the underlying output stream to which the response is written |
| 1620 | */ |
| 1621 | public OutputStream getOutputStream() { return out; } |
| 1622 | |
| 1623 | /** |
| 1624 | * Returns whether the response headers were already sent. |
| 1625 | * |
| 1626 | * @return whether the response headers were already sent |
| 1627 | */ |
| 1628 | public boolean headersSent() { return state == 1; } |
| 1629 |
nothing calls this directly
no outgoing calls
no test coverage detected