ap_bgetopt (r->connection->client, BO_BYTECT, &r->bytes_sent); \
} while (0)
+
+/* if this is the first error, then log an INFO message and shut down the
+ * connection.
+ */
+static void check_first_conn_error(const request_rec *r, const char *operation,
+ ap_status_t status)
+{
+ if (!r->connection->aborted) {
+ if (status == 0)
+ status = ap_berror(r->connection->client);
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, status, r,
+ "client stopped connection before %s completed",
+ operation);
+ ap_bsetflag(r->connection->client, B_EOUT, 1);
+ r->connection->aborted = 1;
+ }
+}
+
+static int checked_bputstrs(request_rec *r, ...)
+{
+ va_list va;
+ int n;
+
+ if (r->connection->aborted)
+ return EOF;
+
+ va_start(va, r);
+ n = ap_vbputstrs(r->connection->client, va);
+ va_end(va);
+
+ if (n < 0) {
+ check_first_conn_error(r, "checked_bputstrs", 0);
+ return EOF;
+ }
+
+ SET_BYTES_SENT(r);
+ return n;
+}
+
+static int checked_bflush(request_rec *r)
+{
+ ap_status_t rv;
+
+ if ((rv = ap_bflush(r->connection->client)) != APR_SUCCESS) {
+ check_first_conn_error(r, "checked_bflush", rv);
+ return EOF;
+ }
+ return 0;
+}
+
+static int checked_bputs(const char *str, request_rec *r)
+{
+ int rcode;
+
+ if (r->connection->aborted)
+ return EOF;
+
+ rcode = ap_bputs(str, r->connection->client);
+ if (rcode < 0) {
+ check_first_conn_error(r, "checked_bputs", 0);
+ return EOF;
+ }
+ SET_BYTES_SENT(r);
+ return rcode;
+}
+
/*
* Builds the content-type that should be sent to the client from the
* content-type specified. The following rules are followed:
if (!**r_range) {
if (r->byterange > 1) {
- if (realreq)
- ap_rvputs(r, CRLF "--", r->boundary, "--" CRLF, NULL);
- else
+ if (realreq) {
+ /* ### this isn't "content" so we can't use ap_rvputs(), but
+ * ### it should be processed by non-processing filters. We
+ * ### have no "in-between" APIs yet, so send it to the
+ * ### network for now
+ */
+ (void) checked_bputstrs(r, CRLF "--", r->boundary, "--" CRLF,
+ NULL);
+ } else {
*tlength += 4 + strlen(r->boundary) + 4;
+ }
}
#ifdef APACHE_XLATE
AP_POP_OUTPUTCONVERSION_STATE(r->connection->client);
ap_snprintf(ts, sizeof(ts), "%ld-%ld/%ld", range_start, range_end,
r->clength);
if (realreq)
- ap_rvputs(r, CRLF "--", r->boundary, CRLF "Content-type: ",
- ct, CRLF "Content-range: bytes ", ts, CRLF CRLF,
- NULL);
+ (void) checked_bputstrs(r, CRLF "--", r->boundary,
+ CRLF "Content-type: ", ct,
+ CRLF "Content-range: bytes ", ts,
+ CRLF CRLF, NULL);
else
*tlength += 4 + strlen(r->boundary) + 16 + strlen(ct) + 23 +
strlen(ts) + 4;
API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r,
const char *fieldname, const char *fieldval)
{
- return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
+ return (0 < checked_bputstrs(r, fieldname, ": ", fieldval, CRLF, NULL));
}
API_EXPORT(void) ap_basic_http_header(request_rec *r)
/* Output the HTTP/1.x Status-Line and the Date and Server fields */
- ap_rvputs(r, protocol, " ", r->status_line, CRLF, NULL);
+ (void) checked_bputstrs(r, protocol, " ", r->status_line, CRLF, NULL);
date = ap_palloc(r->pool, AP_RFC822_DATE_LEN);
ap_rfc822_date(date, r->request_time);
ap_bgetopt(r->connection->client, BO_BYTECT, &bs);
if (bs >= 255 && bs <= 257)
- ap_rputs("X-Pad: avoid browser bug" CRLF, r);
+ (void) checked_bputs("X-Pad: avoid browser bug" CRLF, r);
- ap_rputs(CRLF, r); /* Send the terminating empty line */
+ (void) checked_bputs(CRLF, r); /* Send the terminating empty line */
}
/* Build the Allow field-value from the request handler method mask.
#endif /*APACHE_XLATE*/
}
+static void flush_filters(request_rec *r)
+{
+ /* ### place holder to flush pending content through the filters */
+}
+
/* finalize_request_protocol is called at completion of sending the
* response. It's sole purpose is to send the terminating protocol
* information for any wrappers around the response message body
*/
API_EXPORT(void) ap_finalize_request_protocol(request_rec *r)
{
+ flush_filters(r);
+
if (r->chunked && !r->connection->aborted) {
#ifdef APACHE_XLATE
AP_PUSH_OUTPUTCONVERSION_STATE(r->connection->client,
r->chunked = 0;
ap_bsetflag(r->connection->client, B_CHUNK, 0);
- ap_rputs("0" CRLF, r);
+ (void) checked_bputs("0" CRLF, r);
+
/* If we had footer "headers", we'd send them now */
- ap_rputs(CRLF, r);
+ /* ### these need to be added to allow message digests */
+
+ (void) checked_bputs(CRLF, r);
#ifdef APACHE_XLATE
AP_POP_OUTPUTCONVERSION_STATE(r->connection->client);
if (r->expecting_100 && r->proto_num >= HTTP_VERSION(1,1)) {
/* sending 100 Continue interim response */
- ap_rvputs(r, AP_SERVER_PROTOCOL, " ", status_lines[0], CRLF CRLF,
- NULL);
- ap_rflush(r);
+ (void) checked_bputstrs(r, AP_SERVER_PROTOCOL, " ", status_lines[0],
+ CRLF CRLF, NULL);
+ (void) checked_bflush(r);
}
return 1;
return OK;
}
-/* if this is the first error, then log an INFO message and shut down the
- * connection.
- */
-static void check_first_conn_error(const request_rec *r, const char *operation,
- ap_status_t status)
-{
- if (!r->connection->aborted) {
- if (status == 0)
- status = ap_berror(r->connection->client);
- ap_log_rerror(APLOG_MARK, APLOG_INFO, status, r,
- "client stopped connection before %s completed",
- operation);
- ap_bsetflag(r->connection->client, B_EOUT, 1);
- r->connection->aborted = 1;
- }
-}
-
/*
* Send the body of a response to the client.
*/
char buf[IOBUFSIZE];
long total_bytes_sent = 0;
register int o;
- ap_ssize_t w;
ap_ssize_t n;
ap_status_t rv;
while (!r->connection->aborted) {
if ((length > 0) && (total_bytes_sent + IOBUFSIZE) > length)
- o = length - total_bytes_sent;
+ n = length - total_bytes_sent;
else
- o = IOBUFSIZE;
+ n = IOBUFSIZE;
- n = o;
do {
rv = ap_read(fd, buf, &n);
} while (rv == APR_EINTR && !r->connection->aborted);
break;
}
- o = 0;
-
- while (n && !r->connection->aborted) {
- rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
- if (w > 0) {
- total_bytes_sent += w;
- n -= w;
- o += w;
- }
- else if (rv != APR_SUCCESS) {
- check_first_conn_error(r, "send-body", rv);
- break;
- }
- }
+ o = ap_rwrite(buf, n, r);
+ if (o < 0)
+ break;
+ total_bytes_sent += o;
}
SET_BYTES_SENT(r);
long total_bytes_sent = 0;
long zero_timeout = 0;
register int o;
- ap_ssize_t w;
ap_ssize_t n;
ap_ssize_t bytes_read;
- ap_status_t rv;
ap_status_t read_rv;
if (length == 0) {
got_read:
bytes_read = n;
/* Regardless of read errors, EOF, etc, bytes may have been read */
- o = 0;
- while (n && !r->connection->aborted) {
- rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
- if (w > 0) {
- total_bytes_sent += w;
- n -= w;
- o += w;
- }
- else if (rv != APR_SUCCESS) {
- check_first_conn_error(r, "rflush", rv);
- break;
- }
- }
+ o = ap_rwrite(buf, n, r);
+ if (o < 0)
+ break;
+ total_bytes_sent += o;
if (read_rv == APR_SUCCESS) {
/* Assume a sucessful read of 0 bytes is an EOF
* Note: I don't think this is ultimately the right thing.
size_t total_bytes_sent = 0;
int n;
ap_ssize_t w;
- ap_status_t rv;
char *addr;
if (length == 0)
n = length - offset;
}
- while (n && !r->connection->aborted) {
- ap_mmap_offset((void**)&addr, mm, offset);
- rv = ap_bwrite(r->connection->client, addr, n, &w);
- if (w > 0) {
- total_bytes_sent += w;
- n -= w;
- offset += w;
- }
- else if (rv != APR_SUCCESS) {
- if (r->connection->aborted)
- break;
- else if (ap_canonical_error(rv) == APR_EAGAIN)
- continue;
- else {
- check_first_conn_error(r, "send-mmap", rv);
- break;
- }
- }
- }
+ ap_mmap_offset((void**)&addr, mm, offset);
+ w = ap_rwrite(addr, n, r);
+ if (w < 0)
+ break;
+ total_bytes_sent += w;
+ offset += w;
}
SET_BYTES_SENT(r);
if (r->connection->aborted)
return EOF;
+ /* ### should loop to avoid partial writes */
rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
if (n < 0) {
check_first_conn_error(r, "rwrite", rv);