]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- code cleanup (Ranges)
authorrousskov <>
Wed, 3 Jun 1998 04:15:18 +0000 (04:15 +0000)
committerrousskov <>
Wed, 3 Jun 1998 04:15:18 +0000 (04:15 +0000)
- added HDR_IF_RANGE field (no actual processing yet)

src/HttpHeader.cc
src/client_side.cc
src/enums.h

index f655d837a27484356c6860923ca3e6e0c5e2cb7a..17ef890c784630065040a2c98a42fc4b187a87ec 100644 (file)
@@ -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 */
index 707d484bafd6aecd0ac3344af9c6f4bdf9492756..4d74e277f19da35f2a3f7a750904c6a958f2e632 100644 (file)
@@ -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());
index 587e0f73eb32a1ad2dd3e4966bf10386cfcdd55c..a3780bbdab5afa9ed82f8caa02e81b8db48178f9 100644 (file)
@@ -205,6 +205,7 @@ typedef enum {
     HDR_FROM,
     HDR_HOST,
     HDR_IF_MODIFIED_SINCE,
+    HDR_IF_RANGE,
     HDR_LAST_MODIFIED,
     HDR_LINK,
     HDR_LOCATION,