/*
- * $Id: HttpHeader.cc,v 1.40 1998/06/02 21:38:05 rousskov Exp $
+ * $Id: HttpHeader.cc,v 1.41 1998/06/02 22:15:18 rousskov Exp $
*
* DEBUG: section 55 HTTP Header
* AUTHOR: Alex Rousskov
{"From", HDR_FROM, ftStr},
{"Host", HDR_HOST, ftStr},
{"If-Modified-Since", HDR_IF_MODIFIED_SINCE, ftDate_1123},
+ {"If-Range", HDR_IF_RANGE, ftDate_1123}, /* for now (ftDate_1123 or ftStr!) */
{"Last-Modified", HDR_LAST_MODIFIED, ftDate_1123},
{"Link", HDR_LINK, ftStr},
{"Location", HDR_LOCATION, ftStr},
static http_hdr_type RequestHeadersArr[] =
{
HDR_AUTHORIZATION, HDR_FROM, HDR_HOST, HDR_IF_MODIFIED_SINCE,
- HDR_MAX_FORWARDS, HDR_PROXY_CONNECTION, HDR_PROXY_AUTHORIZATION,
- HDR_RANGE, HDR_REFERER, HDR_USER_AGENT, HDR_X_FORWARDED_FOR
+ HDR_IF_RANGE, HDR_MAX_FORWARDS, HDR_PROXY_CONNECTION,
+ HDR_PROXY_AUTHORIZATION, HDR_RANGE, HDR_REFERER, HDR_USER_AGENT,
+ HDR_X_FORWARDED_FOR
};
/* header accounting */
/*
- * $Id: client_side.cc,v 1.323 1998/06/02 21:38:07 rousskov Exp $
+ * $Id: client_side.cc,v 1.324 1998/06/02 22:15:19 rousskov Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
}
#endif
+/* adds appropriate Range headers if needed */
+static void
+clientBuildRangeHeader(clientHttpRequest * http, HttpReply * rep)
+{
+ HttpHeader *hdr = &rep->header;
+ const char *range_err = NULL;
+ assert(http->request->range);
+ /* check if we still want to do ranges */
+ if (rep->sline.status != HTTP_OK)
+ range_err = "wrong status code";
+ else
+ if (httpHeaderHas(hdr, HDR_CONTENT_RANGE))
+ range_err = "origin server does ranges";
+ else
+ if (rep->content_length < 0)
+ range_err = "unknown length";
+ else
+ if (rep->content_length != http->entry->mem_obj->reply->content_length)
+ range_err = "INCONSISTENT length"; /* a bug? */
+ else
+ if (!httpHdrRangeCanonize(http->request->range, rep->content_length))
+ range_err = "canonization failed";
+ else
+ if (httpHdrRangeIsComplex(http->request->range))
+ range_err = "too complex range header";
+ /* get rid of our range specs on error */
+ if (range_err) {
+ debug(33, 1) ("clientBuildRangeHeader: will not do ranges: %s.\n", range_err);
+ httpHdrRangeDestroy(http->request->range);
+ http->request->range = NULL;
+ } else {
+ const int spec_count = http->request->range->specs.count;
+ debug(33, 1) ("clientBuildRangeHeader: range spec count: %d clen: %d\n",
+ spec_count, rep->content_length);
+ assert(spec_count > 0);
+ /* append appropriate header(s) */
+ if (spec_count == 1) {
+ HttpHdrRangePos pos = HttpHdrRangeInitPos;
+ HttpHdrRangeSpec spec;
+ assert(httpHdrRangeGetSpec(http->request->range, &spec, &pos));
+ /* append Content-Range */
+ httpHeaderAddContRange(hdr, spec, rep->content_length);
+ /* set new Content-Length to the actual number of OCTETs
+ * transmitted in the message-body */
+ httpHeaderDelById(hdr, HDR_CONTENT_LENGTH);
+ httpHeaderPutInt(hdr, HDR_CONTENT_LENGTH, spec.length);
+ debug(33, 1) ("clientBuildRangeHeader: actual content length: %d\n", spec.length);
+ } else {
+ /* multipart! */
+ /* generate boundary string */
+ http->range_iter.boundary = httpHdrRangeBoundaryStr(http);
+ /* delete old Content-Type, add ours */
+ httpHeaderDelById(hdr, HDR_CONTENT_TYPE);
+ httpHeaderPutStrf(hdr, HDR_CONTENT_TYPE,
+ "multipart/byteranges; boundary=\"%s\"",
+ strBuf(http->range_iter.boundary));
+ /* no need for Content-Length in multipart responses */
+ }
+ }
+}
+
/* filters out unwanted entries from original reply header
* adds extra entries if we have more info than origin server
* adds Squid specific entries */
stringClean(&strConnection);
}
/* Handle Ranges */
- /* move this "if" to a separate function! @?@ @?@ */
- if (http->request->range) {
- const int spec_count = http->request->range->specs.count;
- const char *range_err = NULL;
- debug(33, 1) ("clientBuildReplyHeader: range spec count: %d clen: %d\n",
- spec_count, rep->content_length);
- /* check if we still want to do ranges */
- if (rep->sline.status != HTTP_OK)
- range_err = "wrong status code";
- else
- if (httpHeaderHas(hdr, HDR_CONTENT_RANGE))
- range_err = "origin server does ranges";
- else
- if (rep->content_length < 0)
- range_err = "unknown length";
- else
- if (rep->content_length != http->entry->mem_obj->reply->content_length)
- range_err = "INCONSISTENT length"; /* bug? */
- else
- if (!httpHdrRangeCanonize(http->request->range, rep->content_length))
- range_err = "canonization failed";
- else
- if (httpHdrRangeIsComplex(http->request->range))
- range_err = "too complex range header";
- /* get rid of our range specs on error */
- if (range_err) {
- debug(33, 1) ("clientBuildReplyHeader: will not do ranges: %s.\n", range_err);
- httpHdrRangeDestroy(http->request->range);
- http->request->range = NULL;
- }
- /* if we still want to do ranges, append appropriate header(s) */
- if (http->request->range) {
- assert(spec_count > 0);
- if (spec_count == 1) {
- HttpHdrRangePos pos = HttpHdrRangeInitPos;
- HttpHdrRangeSpec spec;
- assert(httpHdrRangeGetSpec(http->request->range, &spec, &pos));
- /* append Content-Range */
- httpHeaderAddContRange(hdr, spec, rep->content_length);
- /* set new Content-Length to the actual number of OCTETs
- * transmitted in the message-body */
- httpHeaderDelById(hdr, HDR_CONTENT_LENGTH);
- httpHeaderPutInt(hdr, HDR_CONTENT_LENGTH, spec.length);
- debug(33, 1) ("clientBuildReplyHeader: actual content length: %d\n", spec.length);
- } else {
- /* multipart! */
- /* generate boundary string */
- http->range_iter.boundary = httpHdrRangeBoundaryStr(http);
- /* delete old Content-Type, add ours */
- httpHeaderDelById(hdr, HDR_CONTENT_TYPE);
- httpHeaderPutStrf(hdr, HDR_CONTENT_TYPE,
- "multipart/byteranges; boundary=\"%s\"",
- strBuf(http->range_iter.boundary));
- /* no need for Content-Length in multipart responses */
- }
- }
- }
+ if (http->request->range)
+ clientBuildRangeHeader(http, rep);
/* Append X-Cache */
httpHeaderPutStrf(hdr, HDR_X_CACHE, "%s from %s",
is_hit ? "HIT" : "MISS", getMyHostname());