From: rousskov <> Date: Wed, 3 Jun 1998 04:15:18 +0000 (+0000) Subject: - code cleanup (Ranges) X-Git-Tag: SQUID_3_0_PRE1~3194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e17d81d3617f3a7ee4ad392767c07bd3ddfc36d6;p=thirdparty%2Fsquid.git - code cleanup (Ranges) - added HDR_IF_RANGE field (no actual processing yet) --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index f655d837a2..17ef890c78 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -99,6 +99,7 @@ static const HttpHeaderFieldAttrs HeadersAttrs[] = {"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}, @@ -193,8 +194,9 @@ static HttpHeaderMask RequestHeadersMask; /* set run-time using RequestHeaders * 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 */ diff --git a/src/client_side.cc b/src/client_side.cc index 707d484baf..4d74e277f1 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -1057,6 +1057,67 @@ clientBuildReplyHeader(clientHttpRequest * http, } #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 */ @@ -1092,63 +1153,8 @@ clientBuildReplyHeader(clientHttpRequest * http, HttpReply * rep) 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()); diff --git a/src/enums.h b/src/enums.h index 587e0f73eb..a3780bbdab 100644 --- a/src/enums.h +++ b/src/enums.h @@ -205,6 +205,7 @@ typedef enum { HDR_FROM, HDR_HOST, HDR_IF_MODIFIED_SINCE, + HDR_IF_RANGE, HDR_LAST_MODIFIED, HDR_LINK, HDR_LOCATION,