4 * DEBUG: section 64 HTTP Range Header
5 * AUTHOR: Alex Rousskov
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 //#include "client_side_request.h"
41 /** \todo CLEANUP: This file shoudl be called something_stub.cc */
43 #include "HttpHeaderRange.h"
44 #include "HttpHeader.h"
48 #include "ACLChecklist.h"
60 SQUIDCEXTERN
void httpHeaderPutStr(HttpHeader
* hdr
, http_hdr_type type
, const char *str
)
62 fatal ("dummy function\n");
65 SQUIDCEXTERN HttpHeaderEntry
*httpHeaderGetEntry(const HttpHeader
* hdr
, HttpHeaderPos
* pos
)
67 fatal ("dummy function\n");
71 extern String
httpHeaderGetList(const HttpHeader
* hdr
, http_hdr_type id
)
73 fatal ("dummy function\n");
77 SQUIDCEXTERN
int httpHeaderHas(const HttpHeader
* hdr
, http_hdr_type type
)
79 fatal ("dummy function\n");
83 SQUIDCEXTERN
void httpHeaderPutContRange(HttpHeader
* hdr
, const HttpHdrContRange
* cr
)
85 fatal ("dummy function\n");
89 testRangeParser(char const *rangestring
)
91 String
aString (rangestring
);
92 HttpHdrRange
*range
= HttpHdrRange::ParseCreate (&aString
);
97 HttpHdrRange
copy(*range
);
99 assert (copy
.specs
.count
== range
->specs
.count
);
101 HttpHdrRange::iterator pos
= range
->begin();
109 rangeFromString(char const *rangestring
)
111 String
aString (rangestring
);
112 HttpHdrRange
*range
= HttpHdrRange::ParseCreate (&aString
);
123 HttpHdrRange
*range
=rangeFromString("bytes=0-3, 1-, -2");
124 assert (range
->specs
.count
== 3);
126 HttpHdrRange::iterator i
= range
->begin();
128 while (i
!= range
->end()) {
133 assert (counter
== 3);
135 assert (i
- range
->begin() == 0);
137 assert (i
- range
->begin() == 1);
138 assert (i
- range
->end() == -2);
142 testRangeCanonization()
144 HttpHdrRange
*range
=rangeFromString("bytes=0-3, 1-, -2");
145 assert (range
->specs
.count
== 3);
147 /* 0-3 needs a content length of 4 */
148 /* This passes in the extant code - but should it? */
150 if (!range
->canonize(3))
153 assert (range
->specs
.count
== 3);
157 range
=rangeFromString("bytes=0-3, 1-, -2");
159 assert (range
->specs
.count
== 3);
161 /* 0-3 needs a content length of 4 */
162 if (!range
->canonize(4))
167 range
=rangeFromString("bytes=3-6");
169 assert (range
->specs
.count
== 1);
171 /* 3-6 needs a content length of 4 or more */
172 if (range
->canonize(3))
177 range
=rangeFromString("bytes=3-6");
179 assert (range
->specs
.count
== 1);
181 /* 3-6 needs a content length of 4 or more */
182 if (!range
->canonize(4))
187 range
=rangeFromString("bytes=1-1,2-3");
189 assert (range
->specs
.count
== 2);
191 if (!range
->canonize(4))
194 assert (range
->specs
.count
== 2);
200 main (int argc
, char **argv
)
203 /* enable for debugging to console */
204 // _db_init (NULL, NULL);
205 // Debug::Levels[64] = 9;
206 testRangeParser ("bytes=0-3");
207 testRangeParser ("bytes=-3");
208 testRangeParser ("bytes=1-");
209 testRangeParser ("bytes=0-3, 1-, -2");
211 testRangeCanonization();