001: /*
002: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.lib.http;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.lib.aSocket.*;
029: import seda.sandStorm.core.*;
030:
031: import java.util.*;
032: import java.io.*;
033: import java.net.*;
034:
035: /**
036: * This class is used to wrap an HTTP response along with the
037: * connection which it is destined for.
038: *
039: * @author Matt Welsh
040: * @see httpResponse
041: * @see httpConnection
042: */
043: public class httpResponder implements httpConst, QueueElementIF {
044:
045: private httpResponse resp;
046: private httpConnection conn;
047: private boolean closeConnection;
048: private boolean sendHeader;
049:
050: /**
051: * Create an httpResponder with the given response and connection.
052: * @param closeConnection Indicate that the connection should be
053: * closed after sending this response.
054: * @param sendHeader Indicate that the header of the response should
055: * be sent along with the payload.
056: */
057: public httpResponder(httpResponse resp, httpConnection conn,
058: boolean closeConnection, boolean sendHeader) {
059: this .resp = resp;
060: this .conn = conn;
061: this .closeConnection = closeConnection;
062: this .sendHeader = sendHeader;
063: }
064:
065: /**
066: * Create an httpResponder with the given response and connection.
067: * @param closeConnection Indicate that the connection should be
068: * closed after sending this response.
069: */
070: public httpResponder(httpResponse resp, httpConnection conn,
071: boolean closeConnection) {
072: this .resp = resp;
073: this .conn = conn;
074: this .closeConnection = closeConnection;
075: this .sendHeader = true;
076: }
077:
078: /**
079: * Create an httpResponder with the given response and connection.
080: */
081: public httpResponder(httpResponse resp, httpConnection conn) {
082: this (resp, conn, false, true);
083: }
084:
085: /**
086: * Create an httpResponder with the given response, with the
087: * connection being derived from the given request.
088: * @param closeConnection Indicate that the connection should be
089: * closed after sending this response.
090: * @param sendHeader Indicate that the header of the response should
091: * be sent along with the payload.
092: */
093: public httpResponder(httpResponse resp, httpRequest req,
094: boolean closeConnection, boolean sendHeader) {
095: this (resp, req.getConnection(), closeConnection, sendHeader);
096: }
097:
098: /**
099: * Create an httpResponder with the given response, with the
100: * connection being derived from the given request.
101: * @param closeConnection Indicate that the connection should be
102: * closed after sending this response.
103: */
104: public httpResponder(httpResponse resp, httpRequest req,
105: boolean closeConnection) {
106: this (resp, req.getConnection(), closeConnection);
107: }
108:
109: /**
110: * Create an httpResponder with the given response, with the
111: * connection being derived from the given request.
112: */
113: public httpResponder(httpResponse resp, httpRequest req) {
114: this (resp, req.getConnection(),
115: ((req.getHttpVer() < httpRequest.HTTPVER_11) ? (true)
116: : (false)));
117: }
118:
119: /**
120: * Return the connection for this responder.
121: */
122: public httpConnection getConnection() {
123: return conn;
124: }
125:
126: /**
127: * Return the response for this responder.
128: */
129: public httpResponse getResponse() {
130: return resp;
131: }
132:
133: /**
134: * Returns whether the connection should be closed after sending this
135: * response.
136: */
137: public boolean shouldClose() {
138: return closeConnection;
139: }
140:
141: /**
142: * Returns whether the response header should be sent.
143: */
144: public boolean sendHeader() {
145: return sendHeader;
146: }
147:
148: }
|