]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http.cc
Author: Various Translators
[thirdparty/squid.git] / src / http.cc
1
2 /*
3 * $Id$
4 *
5 * DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
6 * AUTHOR: Harvest Derived
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 /*
37 * Anonymizing patch by lutz@as-node.jena.thur.de
38 * have a look into http-anon.c to get more informations.
39 */
40
41 #include "squid.h"
42 #include "errorpage.h"
43 #include "MemBuf.h"
44 #include "http.h"
45 #include "auth/UserRequest.h"
46 #include "Store.h"
47 #include "HttpReply.h"
48 #include "HttpRequest.h"
49 #include "MemObject.h"
50 #include "HttpHdrContRange.h"
51 #include "HttpHdrSc.h"
52 #include "HttpHdrScTarget.h"
53 #include "acl/FilledChecklist.h"
54 #include "fde.h"
55 #if DELAY_POOLS
56 #include "DelayPools.h"
57 #endif
58 #include "SquidTime.h"
59 #include "TextException.h"
60
61 #define SQUID_ENTER_THROWING_CODE() try {
62 #define SQUID_EXIT_THROWING_CODE(status) \
63 status = true; \
64 } \
65 catch (const std::exception &e) { \
66 debugs (11, 1, "Exception error:" << e.what()); \
67 status = false; \
68 }
69
70 CBDATA_CLASS_INIT(HttpStateData);
71
72 static const char *const crlf = "\r\n";
73
74 static void httpMaybeRemovePublic(StoreEntry *, http_status);
75 static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, HttpRequest * request, const HttpRequest * orig_request,
76 HttpHeader * hdr_out, const int we_do_ranges, const http_state_flags);
77
78 HttpStateData::HttpStateData(FwdState *theFwdState) : AsyncJob("HttpStateData"), ServerStateData(theFwdState),
79 lastChunk(0), header_bytes_read(0), reply_bytes_read(0), httpChunkDecoder(NULL)
80 {
81 debugs(11,5,HERE << "HttpStateData " << this << " created");
82 ignoreCacheControl = false;
83 surrogateNoStore = false;
84 fd = fwd->server_fd;
85 readBuf = new MemBuf;
86 readBuf->init(4096, SQUID_TCP_SO_RCVBUF);
87 orig_request = HTTPMSGLOCK(fwd->request);
88
89 if (fwd->servers)
90 _peer = fwd->servers->_peer; /* might be NULL */
91
92 if (_peer) {
93 const char *url;
94
95 if (_peer->options.originserver)
96 url = orig_request->urlpath.termedBuf();
97 else
98 url = entry->url();
99
100 HttpRequest * proxy_req = new HttpRequest(orig_request->method,
101 orig_request->protocol, url);
102
103 proxy_req->SetHost(_peer->host);
104
105 proxy_req->port = _peer->http_port;
106
107 proxy_req->flags = orig_request->flags;
108
109 proxy_req->lastmod = orig_request->lastmod;
110
111 proxy_req->flags.proxying = 1;
112
113 HTTPMSGUNLOCK(request);
114
115 request = HTTPMSGLOCK(proxy_req);
116
117 /*
118 * This NEIGHBOR_PROXY_ONLY check probably shouldn't be here.
119 * We might end up getting the object from somewhere else if,
120 * for example, the request to this neighbor fails.
121 */
122 if (_peer->options.proxy_only)
123 entry->releaseRequest();
124
125 #if DELAY_POOLS
126
127 entry->setNoDelay(_peer->options.no_delay);
128
129 #endif
130 }
131
132 /*
133 * register the handler to free HTTP state data when the FD closes
134 */
135 typedef CommCbMemFunT<HttpStateData, CommCloseCbParams> Dialer;
136 closeHandler = asyncCall(9, 5, "httpStateData::httpStateConnClosed",
137 Dialer(this,&HttpStateData::httpStateConnClosed));
138 comm_add_close_handler(fd, closeHandler);
139 }
140
141 HttpStateData::~HttpStateData()
142 {
143 /*
144 * don't forget that ~ServerStateData() gets called automatically
145 */
146
147 if (!readBuf->isNull())
148 readBuf->clean();
149
150 delete readBuf;
151
152 if (httpChunkDecoder)
153 delete httpChunkDecoder;
154
155 HTTPMSGUNLOCK(orig_request);
156
157 debugs(11,5, HERE << "HttpStateData " << this << " destroyed; FD " << fd);
158 }
159
160 int
161 HttpStateData::dataDescriptor() const
162 {
163 return fd;
164 }
165 /*
166 static void
167 httpStateFree(int fd, void *data)
168 {
169 HttpStateData *httpState = static_cast<HttpStateData *>(data);
170 debugs(11, 5, "httpStateFree: FD " << fd << ", httpState=" << data);
171 delete httpState;
172 }*/
173
174 void
175 HttpStateData::httpStateConnClosed(const CommCloseCbParams &params)
176 {
177 debugs(11, 5, "httpStateFree: FD " << params.fd << ", httpState=" << params.data);
178 deleteThis("HttpStateData::httpStateConnClosed");
179 }
180
181 int
182 httpCachable(const HttpRequestMethod& method)
183 {
184 /* GET and HEAD are cachable. Others are not. */
185
186 // TODO: replase to HttpRequestMethod::isCachable() ?
187 if (method != METHOD_GET && method != METHOD_HEAD)
188 return 0;
189
190 /* else cachable */
191 return 1;
192 }
193
194 void
195 HttpStateData::httpTimeout(const CommTimeoutCbParams &params)
196 {
197 debugs(11, 4, "httpTimeout: FD " << fd << ": '" << entry->url() << "'" );
198
199 if (entry->store_status == STORE_PENDING) {
200 fwd->fail(errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, fwd->request));
201 }
202
203 comm_close(fd);
204 }
205
206 static void
207 httpMaybeRemovePublic(StoreEntry * e, http_status status)
208 {
209 int remove = 0;
210 int forbidden = 0;
211 StoreEntry *pe;
212
213 if (!EBIT_TEST(e->flags, KEY_PRIVATE))
214 return;
215
216 switch (status) {
217
218 case HTTP_OK:
219
220 case HTTP_NON_AUTHORITATIVE_INFORMATION:
221
222 case HTTP_MULTIPLE_CHOICES:
223
224 case HTTP_MOVED_PERMANENTLY:
225
226 case HTTP_MOVED_TEMPORARILY:
227
228 case HTTP_GONE:
229
230 case HTTP_NOT_FOUND:
231 remove = 1;
232
233 break;
234
235 case HTTP_FORBIDDEN:
236
237 case HTTP_METHOD_NOT_ALLOWED:
238 forbidden = 1;
239
240 break;
241
242 #if WORK_IN_PROGRESS
243
244 case HTTP_UNAUTHORIZED:
245 forbidden = 1;
246
247 break;
248
249 #endif
250
251 default:
252 #if QUESTIONABLE
253 /*
254 * Any 2xx response should eject previously cached entities...
255 */
256
257 if (status >= 200 && status < 300)
258 remove = 1;
259
260 #endif
261
262 break;
263 }
264
265 if (!remove && !forbidden)
266 return;
267
268 assert(e->mem_obj);
269
270 if (e->mem_obj->request)
271 pe = storeGetPublicByRequest(e->mem_obj->request);
272 else
273 pe = storeGetPublic(e->mem_obj->url, e->mem_obj->method);
274
275 if (pe != NULL) {
276 assert(e != pe);
277 #if USE_HTCP
278 neighborsHtcpClear(e, NULL, e->mem_obj->request, e->mem_obj->method, HTCP_CLR_INVALIDATION);
279 #endif
280 pe->release();
281 }
282
283 /** \par
284 * Also remove any cached HEAD response in case the object has
285 * changed.
286 */
287 if (e->mem_obj->request)
288 pe = storeGetPublicByRequestMethod(e->mem_obj->request, METHOD_HEAD);
289 else
290 pe = storeGetPublic(e->mem_obj->url, METHOD_HEAD);
291
292 if (pe != NULL) {
293 assert(e != pe);
294 #if USE_HTCP
295 neighborsHtcpClear(e, NULL, e->mem_obj->request, HttpRequestMethod(METHOD_HEAD), HTCP_CLR_INVALIDATION);
296 #endif
297 pe->release();
298 }
299 }
300
301 void
302 HttpStateData::processSurrogateControl(HttpReply *reply)
303 {
304 #if USE_SQUID_ESI
305
306 if (request->flags.accelerated && reply->surrogate_control) {
307 HttpHdrScTarget *sctusable =
308 httpHdrScGetMergedTarget(reply->surrogate_control,
309 Config.Accel.surrogate_id);
310
311 if (sctusable) {
312 if (EBIT_TEST(sctusable->mask, SC_NO_STORE) ||
313 (Config.onoff.surrogate_is_remote
314 && EBIT_TEST(sctusable->mask, SC_NO_STORE_REMOTE))) {
315 surrogateNoStore = true;
316 entry->makePrivate();
317 }
318
319 /* The HttpHeader logic cannot tell if the header it's parsing is a reply to an
320 * accelerated request or not...
321 * Still, this is an abtraction breach. - RC
322 */
323 if (sctusable->max_age != -1) {
324 if (sctusable->max_age < sctusable->max_stale)
325 reply->expires = reply->date + sctusable->max_age;
326 else
327 reply->expires = reply->date + sctusable->max_stale;
328
329 /* And update the timestamps */
330 entry->timestampsSet();
331 }
332
333 /* We ignore cache-control directives as per the Surrogate specification */
334 ignoreCacheControl = true;
335
336 httpHdrScTargetDestroy(sctusable);
337 }
338 }
339
340 #endif
341 }
342
343 int
344 HttpStateData::cacheableReply()
345 {
346 HttpReply const *rep = finalReply();
347 HttpHeader const *hdr = &rep->header;
348 const int cc_mask = (rep->cache_control) ? rep->cache_control->mask : 0;
349 const char *v;
350 #if HTTP_VIOLATIONS
351
352 const refresh_t *R = NULL;
353
354 /* This strange looking define first looks up the refresh pattern
355 * and then checks if the specified flag is set. The main purpose
356 * of this is to simplify the refresh pattern lookup and HTTP_VIOLATIONS
357 * condition
358 */
359 #define REFRESH_OVERRIDE(flag) \
360 ((R = (R ? R : refreshLimits(entry->mem_obj->url))) , \
361 (R && R->flags.flag))
362 #else
363 #define REFRESH_OVERRIDE(flag) 0
364 #endif
365
366 if (surrogateNoStore)
367 return 0;
368
369 if (!ignoreCacheControl) {
370 if (EBIT_TEST(cc_mask, CC_PRIVATE)) {
371 if (!REFRESH_OVERRIDE(ignore_private))
372 return 0;
373 }
374
375 if (EBIT_TEST(cc_mask, CC_NO_CACHE)) {
376 if (!REFRESH_OVERRIDE(ignore_no_cache))
377 return 0;
378 }
379
380 if (EBIT_TEST(cc_mask, CC_NO_STORE)) {
381 if (!REFRESH_OVERRIDE(ignore_no_store))
382 return 0;
383 }
384 }
385
386 if (request->flags.auth || request->flags.auth_sent) {
387 /*
388 * Responses to requests with authorization may be cached
389 * only if a Cache-Control: public reply header is present.
390 * RFC 2068, sec 14.9.4
391 */
392
393 if (!EBIT_TEST(cc_mask, CC_PUBLIC)) {
394 if (!REFRESH_OVERRIDE(ignore_auth))
395 return 0;
396 }
397 }
398
399 /* Pragma: no-cache in _replies_ is not documented in HTTP,
400 * but servers like "Active Imaging Webcast/2.0" sure do use it */
401 if (hdr->has(HDR_PRAGMA)) {
402 String s = hdr->getList(HDR_PRAGMA);
403 const int no_cache = strListIsMember(&s, "no-cache", ',');
404 s.clean();
405
406 if (no_cache) {
407 if (!REFRESH_OVERRIDE(ignore_no_cache))
408 return 0;
409 }
410 }
411
412 /*
413 * The "multipart/x-mixed-replace" content type is used for
414 * continuous push replies. These are generally dynamic and
415 * probably should not be cachable
416 */
417 if ((v = hdr->getStr(HDR_CONTENT_TYPE)))
418 if (!strncasecmp(v, "multipart/x-mixed-replace", 25))
419 return 0;
420
421 switch (rep->sline.status) {
422 /* Responses that are cacheable */
423
424 case HTTP_OK:
425
426 case HTTP_NON_AUTHORITATIVE_INFORMATION:
427
428 case HTTP_MULTIPLE_CHOICES:
429
430 case HTTP_MOVED_PERMANENTLY:
431
432 case HTTP_GONE:
433 /*
434 * Don't cache objects that need to be refreshed on next request,
435 * unless we know how to refresh it.
436 */
437
438 if (!refreshIsCachable(entry)) {
439 debugs(22, 3, "refreshIsCachable() returned non-cacheable..");
440 return 0;
441 }
442
443 /* don't cache objects from peers w/o LMT, Date, or Expires */
444 /* check that is it enough to check headers @?@ */
445 if (rep->date > -1)
446 return 1;
447 else if (rep->last_modified > -1)
448 return 1;
449 else if (!_peer)
450 return 1;
451
452 /* @?@ (here and 302): invalid expires header compiles to squid_curtime */
453 else if (rep->expires > -1)
454 return 1;
455 else
456 return 0;
457
458 /* NOTREACHED */
459 break;
460
461 /* Responses that only are cacheable if the server says so */
462
463 case HTTP_MOVED_TEMPORARILY:
464 case HTTP_TEMPORARY_REDIRECT:
465 if (rep->expires > rep->date && rep->date > 0)
466 return 1;
467 else
468 return 0;
469
470 /* NOTREACHED */
471 break;
472
473 /* Errors can be negatively cached */
474
475 case HTTP_NO_CONTENT:
476
477 case HTTP_USE_PROXY:
478
479 case HTTP_BAD_REQUEST:
480
481 case HTTP_FORBIDDEN:
482
483 case HTTP_NOT_FOUND:
484
485 case HTTP_METHOD_NOT_ALLOWED:
486
487 case HTTP_REQUEST_URI_TOO_LARGE:
488
489 case HTTP_INTERNAL_SERVER_ERROR:
490
491 case HTTP_NOT_IMPLEMENTED:
492
493 case HTTP_BAD_GATEWAY:
494
495 case HTTP_SERVICE_UNAVAILABLE:
496
497 case HTTP_GATEWAY_TIMEOUT:
498 return -1;
499
500 /* NOTREACHED */
501 break;
502
503 /* Some responses can never be cached */
504
505 case HTTP_PARTIAL_CONTENT: /* Not yet supported */
506
507 case HTTP_SEE_OTHER:
508
509 case HTTP_NOT_MODIFIED:
510
511 case HTTP_UNAUTHORIZED:
512
513 case HTTP_PROXY_AUTHENTICATION_REQUIRED:
514
515 case HTTP_INVALID_HEADER: /* Squid header parsing error */
516
517 case HTTP_HEADER_TOO_LARGE:
518
519 case HTTP_PAYMENT_REQUIRED:
520 case HTTP_NOT_ACCEPTABLE:
521 case HTTP_REQUEST_TIMEOUT:
522 case HTTP_CONFLICT:
523 case HTTP_LENGTH_REQUIRED:
524 case HTTP_PRECONDITION_FAILED:
525 case HTTP_REQUEST_ENTITY_TOO_LARGE:
526 case HTTP_UNSUPPORTED_MEDIA_TYPE:
527 case HTTP_UNPROCESSABLE_ENTITY:
528 case HTTP_LOCKED:
529 case HTTP_FAILED_DEPENDENCY:
530 case HTTP_INSUFFICIENT_STORAGE:
531 case HTTP_REQUESTED_RANGE_NOT_SATISFIABLE:
532 case HTTP_EXPECTATION_FAILED:
533
534 return 0;
535
536 default: /* Unknown status code */
537 debugs (11, 0, HERE << "HttpStateData::cacheableReply: unexpected http status code " << rep->sline.status);
538
539 return 0;
540
541 /* NOTREACHED */
542 break;
543 }
544
545 /* NOTREACHED */
546 }
547
548 /*
549 * For Vary, store the relevant request headers as
550 * virtual headers in the reply
551 * Returns false if the variance cannot be stored
552 */
553 const char *
554 httpMakeVaryMark(HttpRequest * request, HttpReply const * reply)
555 {
556 String vary, hdr;
557 const char *pos = NULL;
558 const char *item;
559 const char *value;
560 int ilen;
561 static String vstr;
562
563 vstr.clean();
564 vary = reply->header.getList(HDR_VARY);
565
566 while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
567 char *name = (char *)xmalloc(ilen + 1);
568 xstrncpy(name, item, ilen + 1);
569 Tolower(name);
570
571 if (strcmp(name, "*") == 0) {
572 /* Can not handle "Vary: *" withtout ETag support */
573 safe_free(name);
574 vstr.clean();
575 break;
576 }
577
578 strListAdd(&vstr, name, ',');
579 hdr = request->header.getByName(name);
580 safe_free(name);
581 value = hdr.termedBuf();
582
583 if (value) {
584 value = rfc1738_escape_part(value);
585 vstr.append("=\"", 2);
586 vstr.append(value);
587 vstr.append("\"", 1);
588 }
589
590 hdr.clean();
591 }
592
593 vary.clean();
594 #if X_ACCELERATOR_VARY
595
596 pos = NULL;
597 vary = reply->header.getList(HDR_X_ACCELERATOR_VARY);
598
599 while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
600 char *name = (char *)xmalloc(ilen + 1);
601 xstrncpy(name, item, ilen + 1);
602 Tolower(name);
603 strListAdd(&vstr, name, ',');
604 hdr = request->header.getByName(name);
605 safe_free(name);
606 value = hdr.termedBuf();
607
608 if (value) {
609 value = rfc1738_escape_part(value);
610 vstr.append("=\"", 2);
611 vstr.append(value);
612 vstr.append("\"", 1);
613 }
614
615 hdr.clean();
616 }
617
618 vary.clean();
619 #endif
620
621 debugs(11, 3, "httpMakeVaryMark: " << vstr);
622 return vstr.termedBuf();
623 }
624
625 void
626 HttpStateData::keepaliveAccounting(HttpReply *reply)
627 {
628 if (flags.keepalive)
629 if (_peer)
630 _peer->stats.n_keepalives_sent++;
631
632 if (reply->keep_alive) {
633 if (_peer)
634 _peer->stats.n_keepalives_recv++;
635
636 if (Config.onoff.detect_broken_server_pconns
637 && reply->bodySize(request->method) == -1 && !flags.chunked) {
638 debugs(11, 1, "keepaliveAccounting: Impossible keep-alive header from '" << entry->url() << "'" );
639 // debugs(11, 2, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------" );
640 flags.keepalive_broken = 1;
641 }
642 }
643 }
644
645 void
646 HttpStateData::checkDateSkew(HttpReply *reply)
647 {
648 if (reply->date > -1 && !_peer) {
649 int skew = abs((int)(reply->date - squid_curtime));
650
651 if (skew > 86400)
652 debugs(11, 3, "" << request->GetHost() << "'s clock is skewed by " << skew << " seconds!");
653 }
654 }
655
656 /**
657 * This creates the error page itself.. its likely
658 * that the forward ported reply header max size patch
659 * generates non http conformant error pages - in which
660 * case the errors where should be 'BAD_GATEWAY' etc
661 */
662 void
663 HttpStateData::processReplyHeader()
664 {
665 /** Creates a blank header. If this routine is made incremental, this will not do */
666 Ctx ctx = ctx_enter(entry->mem_obj->url);
667 debugs(11, 3, "processReplyHeader: key '" << entry->getMD5Text() << "'");
668
669 assert(!flags.headers_parsed);
670
671 http_status error = HTTP_STATUS_NONE;
672
673 HttpReply *newrep = new HttpReply;
674 const bool parsed = newrep->parse(readBuf, eof, &error);
675
676 if (!parsed && readBuf->contentSize() > 5 && strncmp(readBuf->content(), "HTTP/", 5) != 0) {
677 MemBuf *mb;
678 HttpReply *tmprep = new HttpReply;
679 tmprep->sline.version = HttpVersion(1, 0);
680 tmprep->sline.status = HTTP_OK;
681 tmprep->header.putTime(HDR_DATE, squid_curtime);
682 tmprep->header.putExt("X-Transformed-From", "HTTP/0.9");
683 mb = tmprep->pack();
684 newrep->parse(mb, eof, &error);
685 delete tmprep;
686 } else {
687 if (!parsed && error > 0) { // unrecoverable parsing error
688 debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << readBuf->content() << "'");
689 flags.headers_parsed = 1;
690 newrep->sline.version = HttpVersion(1, 0);
691 newrep->sline.status = error;
692 HttpReply *vrep = setVirginReply(newrep);
693 entry->replaceHttpReply(vrep);
694 ctx_exit(ctx);
695 return;
696 }
697
698 if (!parsed) { // need more data
699 assert(!error);
700 assert(!eof);
701 delete newrep;
702 ctx_exit(ctx);
703 return;
704 }
705
706 debugs(11, 9, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------");
707
708 header_bytes_read = headersEnd(readBuf->content(), readBuf->contentSize());
709 readBuf->consume(header_bytes_read);
710 }
711
712 flags.chunked = 0;
713 if (newrep->header.hasListMember(HDR_TRANSFER_ENCODING, "chunked", ',')) {
714 flags.chunked = 1;
715 httpChunkDecoder = new ChunkedCodingParser;
716 }
717
718 if (!peerSupportsConnectionPinning())
719 orig_request->flags.connection_auth_disabled = 1;
720
721 HttpReply *vrep = setVirginReply(newrep);
722 flags.headers_parsed = 1;
723
724 keepaliveAccounting(vrep);
725
726 checkDateSkew(vrep);
727
728 processSurrogateControl (vrep);
729
730 /** \todo IF the reply is a 1.0 reply, AND it has a Connection: Header
731 * Parse the header and remove all referenced headers
732 */
733
734 ctx_exit(ctx);
735
736 }
737
738 /**
739 * returns true if the peer can support connection pinning
740 */
741 bool HttpStateData::peerSupportsConnectionPinning() const
742 {
743 const HttpReply *rep = entry->mem_obj->getReply();
744 const HttpHeader *hdr = &rep->header;
745 bool rc;
746 String header;
747
748 if (!_peer)
749 return true;
750
751 /*If this peer does not support connection pinning (authenticated
752 connections) return false
753 */
754 if (!_peer->connection_auth)
755 return false;
756
757 /*The peer supports connection pinning and the http reply status
758 is not unauthorized, so the related connection can be pinned
759 */
760 if (rep->sline.status != HTTP_UNAUTHORIZED)
761 return true;
762
763 /*The server respond with HTTP_UNAUTHORIZED and the peer configured
764 with "connection-auth=on" we know that the peer supports pinned
765 connections
766 */
767 if (_peer->connection_auth == 1)
768 return true;
769
770 /*At this point peer has configured with "connection-auth=auto"
771 parameter so we need some extra checks to decide if we are going
772 to allow pinned connections or not
773 */
774
775 /*if the peer configured with originserver just allow connection
776 pinning (squid 2.6 behaviour)
777 */
778 if (_peer->options.originserver)
779 return true;
780
781 /*if the connections it is already pinned it is OK*/
782 if (request->flags.pinned)
783 return true;
784
785 /*Allow pinned connections only if the Proxy-support header exists in
786 reply and has in its list the "Session-Based-Authentication"
787 which means that the peer supports connection pinning.
788 */
789 if (!hdr->has(HDR_PROXY_SUPPORT))
790 return false;
791
792 header = hdr->getStrOrList(HDR_PROXY_SUPPORT);
793 /* XXX This ought to be done in a case-insensitive manner */
794 rc = (strstr(header.termedBuf(), "Session-Based-Authentication") != NULL);
795
796 return rc;
797 }
798
799 // Called when we parsed (and possibly adapted) the headers but
800 // had not starting storing (a.k.a., sending) the body yet.
801 void
802 HttpStateData::haveParsedReplyHeaders()
803 {
804 ServerStateData::haveParsedReplyHeaders();
805
806 Ctx ctx = ctx_enter(entry->mem_obj->url);
807 HttpReply *rep = finalReply();
808
809 if (rep->sline.status == HTTP_PARTIAL_CONTENT &&
810 rep->content_range)
811 currentOffset = rep->content_range->spec.offset;
812
813 entry->timestampsSet();
814
815 /* Check if object is cacheable or not based on reply code */
816 debugs(11, 3, "haveParsedReplyHeaders: HTTP CODE: " << rep->sline.status);
817
818 if (neighbors_do_private_keys)
819 httpMaybeRemovePublic(entry, rep->sline.status);
820
821 if (rep->header.has(HDR_VARY)
822 #if X_ACCELERATOR_VARY
823 || rep->header.has(HDR_X_ACCELERATOR_VARY)
824 #endif
825 ) {
826 const char *vary = httpMakeVaryMark(orig_request, rep);
827
828 if (!vary) {
829 entry->makePrivate();
830 goto no_cache;
831
832 }
833
834 entry->mem_obj->vary_headers = xstrdup(vary);
835 }
836
837 #if WIP_FWD_LOG
838 fwdStatus(fwd, s);
839
840 #endif
841 /*
842 * If its not a reply that we will re-forward, then
843 * allow the client to get it.
844 */
845 if (!fwd->reforwardableStatus(rep->sline.status))
846 EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
847
848 switch (cacheableReply()) {
849
850 case 1:
851 entry->makePublic();
852 break;
853
854 case 0:
855 entry->makePrivate();
856 break;
857
858 case -1:
859
860 #if HTTP_VIOLATIONS
861 if (Config.negativeTtl > 0)
862 entry->cacheNegatively();
863 else
864 #endif
865 entry->makePrivate();
866
867 break;
868
869 default:
870 assert(0);
871
872 break;
873 }
874
875 no_cache:
876
877 if (!ignoreCacheControl && rep->cache_control) {
878 if (EBIT_TEST(rep->cache_control->mask, CC_PROXY_REVALIDATE))
879 EBIT_SET(entry->flags, ENTRY_REVALIDATE);
880 else if (EBIT_TEST(rep->cache_control->mask, CC_MUST_REVALIDATE))
881 EBIT_SET(entry->flags, ENTRY_REVALIDATE);
882 }
883
884 #if HEADERS_LOG
885 headersLog(1, 0, request->method, rep);
886
887 #endif
888
889 ctx_exit(ctx);
890 }
891
892 HttpStateData::ConnectionStatus
893 HttpStateData::statusIfComplete() const
894 {
895 const HttpReply *rep = virginReply();
896 /** \par
897 * If the reply wants to close the connection, it takes precedence */
898
899 if (httpHeaderHasConnDir(&rep->header, "close"))
900 return COMPLETE_NONPERSISTENT_MSG;
901
902 /** \par
903 * If we didn't send a keep-alive request header, then this
904 * can not be a persistent connection.
905 */
906 if (!flags.keepalive)
907 return COMPLETE_NONPERSISTENT_MSG;
908
909 /** \par
910 * If we haven't sent the whole request then this can not be a persistent
911 * connection.
912 */
913 if (!flags.request_sent) {
914 debugs(11, 1, "statusIfComplete: Request not yet fully sent \"" << RequestMethodStr(orig_request->method) << " " << entry->url() << "\"" );
915 return COMPLETE_NONPERSISTENT_MSG;
916 }
917
918 /** \par
919 * What does the reply have to say about keep-alive?
920 */
921 /**
922 \bug XXX BUG?
923 * If the origin server (HTTP/1.0) does not send a keep-alive
924 * header, but keeps the connection open anyway, what happens?
925 * We'll return here and http.c waits for an EOF before changing
926 * store_status to STORE_OK. Combine this with ENTRY_FWD_HDR_WAIT
927 * and an error status code, and we might have to wait until
928 * the server times out the socket.
929 */
930 if (!rep->keep_alive)
931 return COMPLETE_NONPERSISTENT_MSG;
932
933 return COMPLETE_PERSISTENT_MSG;
934 }
935
936 HttpStateData::ConnectionStatus
937 HttpStateData::persistentConnStatus() const
938 {
939 debugs(11, 3, "persistentConnStatus: FD " << fd << " eof=" << eof);
940 const HttpReply *vrep = virginReply();
941 debugs(11, 5, "persistentConnStatus: content_length=" << vrep->content_length);
942
943 /* If we haven't seen the end of reply headers, we are not done */
944 debugs(11, 5, "persistentConnStatus: flags.headers_parsed=" << flags.headers_parsed);
945
946 if (!flags.headers_parsed)
947 return INCOMPLETE_MSG;
948
949 if (eof) // already reached EOF
950 return COMPLETE_NONPERSISTENT_MSG;
951
952 /** \par
953 * In chunked response we do not know the content length but we are absolutely
954 * sure about the end of response, so we are calling the statusIfComplete to
955 * decide if we can be persistant
956 */
957 if (lastChunk && flags.chunked)
958 return statusIfComplete();
959
960 const int64_t clen = vrep->bodySize(request->method);
961
962 debugs(11, 5, "persistentConnStatus: clen=" << clen);
963
964 /* If the body size is unknown we must wait for EOF */
965 if (clen < 0)
966 return INCOMPLETE_MSG;
967
968 /** \par
969 * If the body size is known, we must wait until we've gotten all of it. */
970 if (clen > 0) {
971 // old technique:
972 // if (entry->mem_obj->endOffset() < vrep->content_length + vrep->hdr_sz)
973 const int64_t body_bytes_read = reply_bytes_read - header_bytes_read;
974 debugs(11,5, "persistentConnStatus: body_bytes_read=" <<
975 body_bytes_read << " content_length=" << vrep->content_length);
976
977 if (body_bytes_read < vrep->content_length)
978 return INCOMPLETE_MSG;
979 }
980
981 /** \par
982 * If there is no message body or we got it all, we can be persistent */
983 return statusIfComplete();
984 }
985
986 /*
987 * This is the callback after some data has been read from the network
988 */
989 /*
990 void
991 HttpStateData::ReadReplyWrapper(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data)
992 {
993 HttpStateData *httpState = static_cast<HttpStateData *>(data);
994 assert (fd == httpState->fd);
995 // assert(buf == readBuf->content());
996 PROF_start(HttpStateData_readReply);
997 httpState->readReply (len, flag, xerrno);
998 PROF_stop(HttpStateData_readReply);
999 }
1000 */
1001
1002 /* XXX this function is too long! */
1003 void
1004 HttpStateData::readReply (const CommIoCbParams &io)
1005 {
1006 int bin;
1007 int clen;
1008 int len = io.size;
1009
1010 assert(fd == io.fd);
1011
1012 flags.do_next_read = 0;
1013
1014 debugs(11, 5, "httpReadReply: FD " << fd << ": len " << len << ".");
1015
1016 // Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us
1017 if (io.flag == COMM_ERR_CLOSING) {
1018 debugs(11, 3, "http socket closing");
1019 return;
1020 }
1021
1022 if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
1023 maybeReadVirginBody();
1024 return;
1025 }
1026
1027 // handle I/O errors
1028 if (io.flag != COMM_OK || len < 0) {
1029 debugs(11, 2, "httpReadReply: FD " << fd << ": read failure: " << xstrerror() << ".");
1030
1031 if (ignoreErrno(io.xerrno)) {
1032 flags.do_next_read = 1;
1033 } else {
1034 ErrorState *err;
1035 err = errorCon(ERR_READ_ERROR, HTTP_BAD_GATEWAY, fwd->request);
1036 err->xerrno = io.xerrno;
1037 fwd->fail(err);
1038 flags.do_next_read = 0;
1039 comm_close(fd);
1040 }
1041
1042 return;
1043 }
1044
1045 // update I/O stats
1046 if (len > 0) {
1047 readBuf->appended(len);
1048 reply_bytes_read += len;
1049 #if DELAY_POOLS
1050
1051 DelayId delayId = entry->mem_obj->mostBytesAllowed();
1052 delayId.bytesIn(len);
1053 #endif
1054
1055 kb_incr(&statCounter.server.all.kbytes_in, len);
1056 kb_incr(&statCounter.server.http.kbytes_in, len);
1057 IOStats.Http.reads++;
1058
1059 for (clen = len - 1, bin = 0; clen; bin++)
1060 clen >>= 1;
1061
1062 IOStats.Http.read_hist[bin]++;
1063 }
1064
1065 /** \par
1066 * Here the RFC says we should ignore whitespace between replies, but we can't as
1067 * doing so breaks HTTP/0.9 replies beginning with witespace, and in addition
1068 * the response splitting countermeasures is extremely likely to trigger on this,
1069 * not allowing connection reuse in the first place.
1070 */
1071 #if DONT_DO_THIS
1072 if (!flags.headers_parsed && len > 0 && fd_table[fd].uses > 1) {
1073 /* Skip whitespace between replies */
1074
1075 while (len > 0 && xisspace(*buf))
1076 xmemmove(buf, buf + 1, len--);
1077
1078 if (len == 0) {
1079 /* Continue to read... */
1080 /* Timeout NOT increased. This whitespace was from previous reply */
1081 flags.do_next_read = 1;
1082 maybeReadVirginBody();
1083 return;
1084 }
1085 }
1086
1087 #endif
1088
1089 if (len == 0) { // reached EOF?
1090 eof = 1;
1091 flags.do_next_read = 0;
1092 }
1093
1094 if (!flags.headers_parsed) { // have not parsed headers yet?
1095 PROF_start(HttpStateData_processReplyHeader);
1096 processReplyHeader();
1097 PROF_stop(HttpStateData_processReplyHeader);
1098
1099 if (!continueAfterParsingHeader()) // parsing error or need more data
1100 return; // TODO: send errors to ICAP
1101
1102 adaptOrFinalizeReply();
1103 }
1104
1105 // kick more reads if needed and/or process the response body, if any
1106 PROF_start(HttpStateData_processReplyBody);
1107 processReplyBody(); // may call serverComplete()
1108 PROF_stop(HttpStateData_processReplyBody);
1109 }
1110
1111 /**
1112 \retval true if we can continue with processing the body or doing ICAP.
1113 */
1114 bool
1115 HttpStateData::continueAfterParsingHeader()
1116 {
1117 if (!flags.headers_parsed && !eof) {
1118 debugs(11, 9, HERE << "needs more at " << readBuf->contentSize());
1119 flags.do_next_read = 1;
1120 /** \retval false If we have not finished parsing the headers and may get more data.
1121 * Schedules more reads to retrieve the missing data.
1122 */
1123 maybeReadVirginBody(); // schedules all kinds of reads; TODO: rename
1124 return false;
1125 }
1126
1127 /** If we are done with parsing, check for errors */
1128
1129 err_type error = ERR_NONE;
1130
1131 if (flags.headers_parsed) { // parsed headers, possibly with errors
1132 // check for header parsing errors
1133 if (HttpReply *vrep = virginReply()) {
1134 const http_status s = vrep->sline.status;
1135 const HttpVersion &v = vrep->sline.version;
1136 if (s == HTTP_INVALID_HEADER && v != HttpVersion(0,9)) {
1137 error = ERR_INVALID_RESP;
1138 } else
1139 if (s == HTTP_HEADER_TOO_LARGE) {
1140 fwd->dontRetry(true);
1141 error = ERR_TOO_BIG;
1142 } else {
1143 return true; // done parsing, got reply, and no error
1144 }
1145 } else {
1146 // parsed headers but got no reply
1147 error = ERR_INVALID_RESP;
1148 }
1149 } else {
1150 assert(eof);
1151 error = readBuf->hasContent() ?
1152 ERR_INVALID_RESP : ERR_ZERO_SIZE_OBJECT;
1153 }
1154
1155 assert(error != ERR_NONE);
1156 entry->reset();
1157 fwd->fail(errorCon(error, HTTP_BAD_GATEWAY, fwd->request));
1158 flags.do_next_read = 0;
1159 comm_close(fd);
1160 return false; // quit on error
1161 }
1162
1163 /**
1164 * Call this when there is data from the origin server
1165 * which should be sent to either StoreEntry, or to ICAP...
1166 */
1167 void
1168 HttpStateData::writeReplyBody()
1169 {
1170 const char *data = readBuf->content();
1171 int len = readBuf->contentSize();
1172 addVirginReplyBody(data, len);
1173 readBuf->consume(len);
1174 }
1175
1176 bool
1177 HttpStateData::decodeAndWriteReplyBody()
1178 {
1179 const char *data = NULL;
1180 int len;
1181 bool status = false;
1182 assert(flags.chunked);
1183 assert(httpChunkDecoder);
1184 SQUID_ENTER_THROWING_CODE();
1185 MemBuf decodedData;
1186 decodedData.init();
1187 const bool done = httpChunkDecoder->parse(readBuf,&decodedData);
1188 len = decodedData.contentSize();
1189 data=decodedData.content();
1190 addVirginReplyBody(data, len);
1191 if (done) {
1192 lastChunk = 1;
1193 flags.do_next_read = 0;
1194 }
1195 SQUID_EXIT_THROWING_CODE(status);
1196 return status;
1197 }
1198
1199 /**
1200 * processReplyBody has two purposes:
1201 * 1 - take the reply body data, if any, and put it into either
1202 * the StoreEntry, or give it over to ICAP.
1203 * 2 - see if we made it to the end of the response (persistent
1204 * connections and such)
1205 */
1206 void
1207 HttpStateData::processReplyBody()
1208 {
1209 AsyncCall::Pointer call;
1210 IpAddress client_addr;
1211 bool ispinned = false;
1212
1213 if (!flags.headers_parsed) {
1214 flags.do_next_read = 1;
1215 maybeReadVirginBody();
1216 return;
1217 }
1218
1219 #if USE_ADAPTATION
1220 if (adaptationAccessCheckPending)
1221 return;
1222
1223 #endif
1224
1225 /*
1226 * At this point the reply headers have been parsed and consumed.
1227 * That means header content has been removed from readBuf and
1228 * it contains only body data.
1229 */
1230 if (flags.chunked) {
1231 if (!decodeAndWriteReplyBody()) {
1232 flags.do_next_read = 0;
1233 serverComplete();
1234 return;
1235 }
1236 } else
1237 writeReplyBody();
1238
1239 if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
1240 /*
1241 * The above writeReplyBody() call could ABORT this entry,
1242 * in that case, the server FD should already be closed.
1243 * there's nothing for us to do.
1244 */
1245 (void) 0;
1246 } else
1247 switch (persistentConnStatus()) {
1248 case INCOMPLETE_MSG:
1249 debugs(11, 5, "processReplyBody: INCOMPLETE_MSG");
1250 /* Wait for more data or EOF condition */
1251 if (flags.keepalive_broken) {
1252 call = NULL;
1253 commSetTimeout(fd, 10, call);
1254 } else {
1255 call = NULL;
1256 commSetTimeout(fd, Config.Timeout.read, call);
1257 }
1258
1259 flags.do_next_read = 1;
1260 break;
1261
1262 case COMPLETE_PERSISTENT_MSG:
1263 debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG");
1264 /* yes we have to clear all these! */
1265 call = NULL;
1266 commSetTimeout(fd, -1, call);
1267 flags.do_next_read = 0;
1268
1269 comm_remove_close_handler(fd, closeHandler);
1270 closeHandler = NULL;
1271 fwd->unregister(fd);
1272
1273 if (orig_request->flags.spoof_client_ip)
1274 client_addr = orig_request->client_addr;
1275
1276
1277 if (request->flags.pinned) {
1278 ispinned = true;
1279 } else if (request->flags.connection_auth && request->flags.auth_sent) {
1280 ispinned = true;
1281 }
1282
1283 if (orig_request->pinnedConnection() && ispinned) {
1284 orig_request->pinnedConnection()->pinConnection(fd, orig_request, _peer,
1285 (request->flags.connection_auth != 0));
1286 } else {
1287 fwd->pconnPush(fd, _peer, request, orig_request->GetHost(), client_addr);
1288 }
1289
1290 fd = -1;
1291
1292 serverComplete();
1293 return;
1294
1295 case COMPLETE_NONPERSISTENT_MSG:
1296 debugs(11, 5, "processReplyBody: COMPLETE_NONPERSISTENT_MSG");
1297 serverComplete();
1298 return;
1299 }
1300
1301 maybeReadVirginBody();
1302 }
1303
1304 void
1305 HttpStateData::maybeReadVirginBody()
1306 {
1307 int read_sz = replyBodySpace(readBuf->spaceSize());
1308
1309 debugs(11,9, HERE << (flags.do_next_read ? "may" : "wont") <<
1310 " read up to " << read_sz << " bytes from FD " << fd);
1311
1312 /*
1313 * why <2? Because delayAwareRead() won't actually read if
1314 * you ask it to read 1 byte. The delayed read request
1315 * just gets re-queued until the client side drains, then
1316 * the I/O thread hangs. Better to not register any read
1317 * handler until we get a notification from someone that
1318 * its okay to read again.
1319 */
1320 if (read_sz < 2) {
1321 if (flags.headers_parsed)
1322 return;
1323 else
1324 read_sz = 1024;
1325 }
1326
1327 if (flags.do_next_read) {
1328 flags.do_next_read = 0;
1329 typedef CommCbMemFunT<HttpStateData, CommIoCbParams> Dialer;
1330 entry->delayAwareRead(fd, readBuf->space(read_sz), read_sz,
1331 asyncCall(11, 5, "HttpStateData::readReply",
1332 Dialer(this, &HttpStateData::readReply)));
1333 }
1334 }
1335
1336 /*
1337 * This will be called when request write is complete.
1338 */
1339 void
1340 HttpStateData::sendComplete(const CommIoCbParams &io)
1341 {
1342 debugs(11, 5, "httpSendComplete: FD " << fd << ": size " << io.size << ": errflag " << io.flag << ".");
1343 #if URL_CHECKSUM_DEBUG
1344
1345 entry->mem_obj->checkUrlChecksum();
1346 #endif
1347
1348 if (io.size > 0) {
1349 fd_bytes(fd, io.size, FD_WRITE);
1350 kb_incr(&statCounter.server.all.kbytes_out, io.size);
1351 kb_incr(&statCounter.server.http.kbytes_out, io.size);
1352 }
1353
1354 if (io.flag == COMM_ERR_CLOSING)
1355 return;
1356
1357 if (io.flag) {
1358 ErrorState *err;
1359 err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request);
1360 err->xerrno = io.xerrno;
1361 fwd->fail(err);
1362 comm_close(fd);
1363 return;
1364 }
1365
1366 /*
1367 * Set the read timeout here because it hasn't been set yet.
1368 * We only set the read timeout after the request has been
1369 * fully written to the server-side. If we start the timeout
1370 * after connection establishment, then we are likely to hit
1371 * the timeout for POST/PUT requests that have very large
1372 * request bodies.
1373 */
1374 typedef CommCbMemFunT<HttpStateData, CommTimeoutCbParams> TimeoutDialer;
1375 AsyncCall::Pointer timeoutCall = asyncCall(11, 5, "HttpStateData::httpTimeout",
1376 TimeoutDialer(this,&HttpStateData::httpTimeout));
1377
1378 commSetTimeout(fd, Config.Timeout.read, timeoutCall);
1379
1380 flags.request_sent = 1;
1381 }
1382
1383 // Close the HTTP server connection. Used by serverComplete().
1384 void
1385 HttpStateData::closeServer()
1386 {
1387 debugs(11,5, HERE << "closing HTTP server FD " << fd << " this " << this);
1388
1389 if (fd >= 0) {
1390 fwd->unregister(fd);
1391 comm_remove_close_handler(fd, closeHandler);
1392 closeHandler = NULL;
1393 comm_close(fd);
1394 fd = -1;
1395 }
1396 }
1397
1398 bool
1399 HttpStateData::doneWithServer() const
1400 {
1401 return fd < 0;
1402 }
1403
1404 /*
1405 * build request headers and append them to a given MemBuf
1406 * used by buildRequestPrefix()
1407 * note: initialised the HttpHeader, the caller is responsible for Clean()-ing
1408 */
1409 void
1410 HttpStateData::httpBuildRequestHeader(HttpRequest * request,
1411 HttpRequest * orig_request,
1412 StoreEntry * entry,
1413 HttpHeader * hdr_out,
1414 http_state_flags flags)
1415 {
1416 /* building buffer for complex strings */
1417 #define BBUF_SZ (MAX_URL+32)
1418 LOCAL_ARRAY(char, bbuf, BBUF_SZ);
1419 LOCAL_ARRAY(char, ntoabuf, MAX_IPSTRLEN);
1420 const HttpHeader *hdr_in = &orig_request->header;
1421 const HttpHeaderEntry *e = NULL;
1422 String strFwd;
1423 HttpHeaderPos pos = HttpHeaderInitPos;
1424 assert (hdr_out->owner == hoRequest);
1425
1426 /* append our IMS header */
1427 if (request->lastmod > -1)
1428 hdr_out->putTime(HDR_IF_MODIFIED_SINCE, request->lastmod);
1429
1430 bool we_do_ranges = decideIfWeDoRanges (orig_request);
1431
1432 String strConnection (hdr_in->getList(HDR_CONNECTION));
1433
1434 while ((e = hdr_in->getEntry(&pos)))
1435 copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, orig_request, hdr_out, we_do_ranges, flags);
1436
1437 /* Abstraction break: We should interpret multipart/byterange responses
1438 * into offset-length data, and this works around our inability to do so.
1439 */
1440 if (!we_do_ranges && orig_request->multipartRangeRequest()) {
1441 /* don't cache the result */
1442 orig_request->flags.cachable = 0;
1443 /* pretend it's not a range request */
1444 delete orig_request->range;
1445 orig_request->range = NULL;
1446 orig_request->flags.range = 0;
1447 }
1448
1449 /* append Via */
1450 if (Config.onoff.via) {
1451 String strVia;
1452 strVia = hdr_in->getList(HDR_VIA);
1453 snprintf(bbuf, BBUF_SZ, "%d.%d %s",
1454 orig_request->http_ver.major,
1455 orig_request->http_ver.minor, ThisCache);
1456 strListAdd(&strVia, bbuf, ',');
1457 hdr_out->putStr(HDR_VIA, strVia.termedBuf());
1458 strVia.clean();
1459 }
1460
1461 #if USE_SQUID_ESI
1462 {
1463 /* Append Surrogate-Capabilities */
1464 String strSurrogate (hdr_in->getList(HDR_SURROGATE_CAPABILITY));
1465 snprintf(bbuf, BBUF_SZ, "%s=\"Surrogate/1.0 ESI/1.0\"",
1466 Config.Accel.surrogate_id);
1467 strListAdd(&strSurrogate, bbuf, ',');
1468 hdr_out->putStr(HDR_SURROGATE_CAPABILITY, strSurrogate.termedBuf());
1469 }
1470 #endif
1471
1472 strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
1473
1474 /** \pre Handle X-Forwarded-For */
1475 if (strcmp(opt_forwarded_for, "delete") != 0) {
1476 if (strcmp(opt_forwarded_for, "on") == 0) {
1477 /** If set to ON - append client IP or 'unknown'. */
1478 strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
1479 if ( orig_request->client_addr.IsNoAddr() )
1480 strListAdd(&strFwd, "unknown", ',');
1481 else
1482 strListAdd(&strFwd, orig_request->client_addr.NtoA(ntoabuf, MAX_IPSTRLEN), ',');
1483 } else if (strcmp(opt_forwarded_for, "off") == 0) {
1484 /** If set to OFF - append 'unknown'. */
1485 strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
1486 strListAdd(&strFwd, "unknown", ',');
1487 } else if (strcmp(opt_forwarded_for, "transparent") == 0) {
1488 /** If set to TRANSPARENT - pass through unchanged. */
1489 strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
1490 } else if (strcmp(opt_forwarded_for, "truncate") == 0) {
1491 /** If set to TRUNCATE - drop existing list and replace with client IP or 'unknown'. */
1492 if ( orig_request->client_addr.IsNoAddr() )
1493 strFwd = "unknown";
1494 else
1495 strFwd = orig_request->client_addr.NtoA(ntoabuf, MAX_IPSTRLEN);
1496 }
1497 if (strFwd.size() > 0)
1498 hdr_out->putStr(HDR_X_FORWARDED_FOR, strFwd.termedBuf());
1499 }
1500 /** If set to DELETE - do not copy through. */
1501 strFwd.clean();
1502
1503 /* append Host if not there already */
1504 if (!hdr_out->has(HDR_HOST)) {
1505 if (orig_request->peer_domain) {
1506 hdr_out->putStr(HDR_HOST, orig_request->peer_domain);
1507 } else if (orig_request->port == urlDefaultPort(orig_request->protocol)) {
1508 /* use port# only if not default */
1509 hdr_out->putStr(HDR_HOST, orig_request->GetHost());
1510 } else {
1511 httpHeaderPutStrf(hdr_out, HDR_HOST, "%s:%d",
1512 orig_request->GetHost(),
1513 (int) orig_request->port);
1514 }
1515 }
1516
1517 /* append Authorization if known in URL, not in header and going direct */
1518 if (!hdr_out->has(HDR_AUTHORIZATION)) {
1519 if (!request->flags.proxying && *request->login) {
1520 httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
1521 base64_encode(request->login));
1522 }
1523 }
1524
1525 /* append Proxy-Authorization if configured for peer, and proxying */
1526 if (request->flags.proxying && orig_request->peer_login &&
1527 !hdr_out->has(HDR_PROXY_AUTHORIZATION)) {
1528 if (*orig_request->peer_login == '*') {
1529 /* Special mode, to pass the username to the upstream cache */
1530 char loginbuf[256];
1531 const char *username = "-";
1532
1533 if (orig_request->extacl_user.size())
1534 username = orig_request->extacl_user.termedBuf();
1535 else if (orig_request->auth_user_request)
1536 username = orig_request->auth_user_request->username();
1537
1538 snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, orig_request->peer_login + 1);
1539
1540 httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
1541 base64_encode(loginbuf));
1542 } else if (strcmp(orig_request->peer_login, "PASS") == 0) {
1543 if (orig_request->extacl_user.size() && orig_request->extacl_passwd.size()) {
1544 char loginbuf[256];
1545 snprintf(loginbuf, sizeof(loginbuf), SQUIDSTRINGPH ":" SQUIDSTRINGPH,
1546 SQUIDSTRINGPRINT(orig_request->extacl_user),
1547 SQUIDSTRINGPRINT(orig_request->extacl_passwd));
1548 httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
1549 base64_encode(loginbuf));
1550 }
1551 } else if (strcmp(orig_request->peer_login, "PROXYPASS") == 0) {
1552 /* Nothing to do */
1553 } else {
1554 httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
1555 base64_encode(orig_request->peer_login));
1556 }
1557 }
1558
1559 /* append WWW-Authorization if configured for peer */
1560 if (flags.originpeer && orig_request->peer_login &&
1561 !hdr_out->has(HDR_AUTHORIZATION)) {
1562 if (strcmp(orig_request->peer_login, "PASS") == 0) {
1563 /* No credentials to forward.. (should have been done above if available) */
1564 } else if (strcmp(orig_request->peer_login, "PROXYPASS") == 0) {
1565 /* Special mode, convert proxy authentication to WWW authentication
1566 * (also applies to authentication provided by external acl)
1567 */
1568 const char *auth = hdr_in->getStr(HDR_PROXY_AUTHORIZATION);
1569
1570 if (auth && strncasecmp(auth, "basic ", 6) == 0) {
1571 hdr_out->putStr(HDR_AUTHORIZATION, auth);
1572 } else if (orig_request->extacl_user.size() && orig_request->extacl_passwd.size()) {
1573 char loginbuf[256];
1574 snprintf(loginbuf, sizeof(loginbuf), SQUIDSTRINGPH ":" SQUIDSTRINGPH,
1575 SQUIDSTRINGPRINT(orig_request->extacl_user),
1576 SQUIDSTRINGPRINT(orig_request->extacl_passwd));
1577 httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
1578 base64_encode(loginbuf));
1579 }
1580 } else if (*orig_request->peer_login == '*') {
1581 /* Special mode, to pass the username to the upstream cache */
1582 char loginbuf[256];
1583 const char *username = "-";
1584
1585 if (orig_request->auth_user_request)
1586 username = orig_request->auth_user_request->username();
1587 else if (orig_request->extacl_user.size())
1588 username = orig_request->extacl_user.termedBuf();
1589
1590 snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, orig_request->peer_login + 1);
1591
1592 httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
1593 base64_encode(loginbuf));
1594 } else {
1595 /* Fixed login string */
1596 httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
1597 base64_encode(orig_request->peer_login));
1598 }
1599 }
1600
1601 /* append Cache-Control, add max-age if not there already */ {
1602 HttpHdrCc *cc = hdr_in->getCc();
1603
1604 if (!cc)
1605 cc = httpHdrCcCreate();
1606
1607 #if 0 /* see bug 2330 */
1608 /* Set no-cache if determined needed but not found */
1609 if (orig_request->flags.nocache)
1610 EBIT_SET(cc->mask, CC_NO_CACHE);
1611 #endif
1612
1613 /* Add max-age only without no-cache */
1614 if (!EBIT_TEST(cc->mask, CC_MAX_AGE) && !EBIT_TEST(cc->mask, CC_NO_CACHE)) {
1615 const char *url =
1616 entry ? entry->url() : urlCanonical(orig_request);
1617 httpHdrCcSetMaxAge(cc, getMaxAge(url));
1618
1619 if (request->urlpath.size())
1620 assert(strstr(url, request->urlpath.termedBuf()));
1621 }
1622
1623 /* Enforce sibling relations */
1624 if (flags.only_if_cached)
1625 EBIT_SET(cc->mask, CC_ONLY_IF_CACHED);
1626
1627 hdr_out->putCc(cc);
1628
1629 httpHdrCcDestroy(cc);
1630 }
1631
1632 /* maybe append Connection: keep-alive */
1633 if (flags.keepalive) {
1634 if (flags.proxying) {
1635 hdr_out->putStr(HDR_PROXY_CONNECTION, "keep-alive");
1636 } else {
1637 hdr_out->putStr(HDR_CONNECTION, "keep-alive");
1638 }
1639 }
1640
1641 /* append Front-End-Https */
1642 if (flags.front_end_https) {
1643 if (flags.front_end_https == 1 || request->protocol == PROTO_HTTPS)
1644 hdr_out->putStr(HDR_FRONT_END_HTTPS, "On");
1645 }
1646
1647 /* Now mangle the headers. */
1648 if (Config2.onoff.mangle_request_headers)
1649 httpHdrMangleList(hdr_out, request, ROR_REQUEST);
1650
1651 strConnection.clean();
1652 }
1653
1654 /**
1655 * Decides whether a particular header may be cloned from the received Clients request
1656 * to our outgoing fetch request.
1657 */
1658 void
1659 copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, HttpRequest * request, const HttpRequest * orig_request, HttpHeader * hdr_out, const int we_do_ranges, const http_state_flags flags)
1660 {
1661 debugs(11, 5, "httpBuildRequestHeader: " << e->name << ": " << e->value );
1662
1663 switch (e->id) {
1664
1665 /** \title RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid should not pass on. */
1666
1667 case HDR_PROXY_AUTHORIZATION:
1668 /** \par Proxy-Authorization:
1669 * Only pass on proxy authentication to peers for which
1670 * authentication forwarding is explicitly enabled
1671 */
1672
1673 if (flags.proxying && orig_request->peer_login &&
1674 (strcmp(orig_request->peer_login, "PASS") == 0 ||
1675 strcmp(orig_request->peer_login, "PROXYPASS") == 0)) {
1676 hdr_out->addEntry(e->clone());
1677 }
1678
1679 break;
1680
1681 /** \title RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid does not pass on. */
1682
1683 case HDR_CONNECTION: /** \par Connection: */
1684 case HDR_TE: /** \par TE: */
1685 case HDR_KEEP_ALIVE: /** \par Keep-Alive: */
1686 case HDR_PROXY_AUTHENTICATE: /** \par Proxy-Authenticate: */
1687 case HDR_TRAILERS: /** \par Trailers: */
1688 case HDR_UPGRADE: /** \par Upgrade: */
1689 case HDR_TRANSFER_ENCODING: /** \par Transfer-Encoding: */
1690 break;
1691
1692
1693 /** \title OTHER headers I haven't bothered to track down yet. */
1694
1695 case HDR_AUTHORIZATION:
1696 /** \par WWW-Authorization:
1697 * Pass on WWW authentication */
1698
1699 if (!flags.originpeer) {
1700 hdr_out->addEntry(e->clone());
1701 } else {
1702 /** \note In accelerators, only forward authentication if enabled
1703 * by login=PASS or login=PROXYPASS
1704 * (see also below for proxy->server authentication)
1705 */
1706 if (orig_request->peer_login &&
1707 (strcmp(orig_request->peer_login, "PASS") == 0 ||
1708 strcmp(orig_request->peer_login, "PROXYPASS") == 0)) {
1709 hdr_out->addEntry(e->clone());
1710 }
1711 }
1712
1713 break;
1714
1715 case HDR_HOST:
1716 /** \par Host:
1717 * Normally Squid rewrites the Host: header.
1718 * However, there is one case when we don't: If the URL
1719 * went through our redirector and the admin configured
1720 * 'redir_rewrites_host' to be off.
1721 */
1722 if (orig_request->peer_domain)
1723 hdr_out->putStr(HDR_HOST, orig_request->peer_domain);
1724 else if (request->flags.redirected && !Config.onoff.redir_rewrites_host)
1725 hdr_out->addEntry(e->clone());
1726 else {
1727 /* use port# only if not default */
1728
1729 if (orig_request->port == urlDefaultPort(orig_request->protocol)) {
1730 hdr_out->putStr(HDR_HOST, orig_request->GetHost());
1731 } else {
1732 httpHeaderPutStrf(hdr_out, HDR_HOST, "%s:%d",
1733 orig_request->GetHost(),
1734 (int) orig_request->port);
1735 }
1736 }
1737
1738 break;
1739
1740 case HDR_IF_MODIFIED_SINCE:
1741 /** \par If-Modified-Since:
1742 * append unless we added our own;
1743 * \note at most one client's ims header can pass through */
1744
1745 if (!hdr_out->has(HDR_IF_MODIFIED_SINCE))
1746 hdr_out->addEntry(e->clone());
1747
1748 break;
1749
1750 case HDR_MAX_FORWARDS:
1751 /** \par Max-Forwards:
1752 * pass only on TRACE requests */
1753 if (orig_request->method == METHOD_TRACE) {
1754 const int hops = e->getInt();
1755
1756 if (hops > 0)
1757 hdr_out->putInt(HDR_MAX_FORWARDS, hops - 1);
1758 }
1759
1760 break;
1761
1762 case HDR_VIA:
1763 /** \par Via:
1764 * If Via is disabled then forward any received header as-is.
1765 * Otherwise leave for explicit updated addition later. */
1766
1767 if (!Config.onoff.via)
1768 hdr_out->addEntry(e->clone());
1769
1770 break;
1771
1772 case HDR_RANGE:
1773
1774 case HDR_IF_RANGE:
1775
1776 case HDR_REQUEST_RANGE:
1777 /** \par Range:, If-Range:, Request-Range:
1778 * Only pass if we accept ranges */
1779 if (!we_do_ranges)
1780 hdr_out->addEntry(e->clone());
1781
1782 break;
1783
1784 case HDR_PROXY_CONNECTION:
1785
1786 case HDR_X_FORWARDED_FOR:
1787
1788 case HDR_CACHE_CONTROL:
1789 /** \par Proxy-Connaction:, X-Forwarded-For:, Cache-Control:
1790 * handled specially by Squid, so leave off for now.
1791 * append these after the loop if needed */
1792 break;
1793
1794 case HDR_FRONT_END_HTTPS:
1795 /** \par Front-End-Https:
1796 * Pass thru only if peer is configured with front-end-https */
1797 if (!flags.front_end_https)
1798 hdr_out->addEntry(e->clone());
1799
1800 break;
1801
1802 default:
1803 /** \par default.
1804 * pass on all other header fields
1805 * which are NOT listed by the special Connection: header. */
1806
1807 if (strConnection.size()>0 && strListIsMember(&strConnection, e->name.termedBuf(), ',')) {
1808 debugs(11, 2, "'" << e->name << "' header cropped by Connection: definition");
1809 return;
1810 }
1811
1812 hdr_out->addEntry(e->clone());
1813 }
1814 }
1815
1816 bool
1817 HttpStateData::decideIfWeDoRanges (HttpRequest * orig_request)
1818 {
1819 bool result = true;
1820 /* decide if we want to do Ranges ourselves
1821 * and fetch the whole object now)
1822 * We want to handle Ranges ourselves iff
1823 * - we can actually parse client Range specs
1824 * - the specs are expected to be simple enough (e.g. no out-of-order ranges)
1825 * - reply will be cachable
1826 * (If the reply will be uncachable we have to throw it away after
1827 * serving this request, so it is better to forward ranges to
1828 * the server and fetch only the requested content)
1829 */
1830
1831 if (NULL == orig_request->range || !orig_request->flags.cachable
1832 || orig_request->range->offsetLimitExceeded() || orig_request->flags.connection_auth)
1833 result = false;
1834
1835 debugs(11, 8, "decideIfWeDoRanges: range specs: " <<
1836 orig_request->range << ", cachable: " <<
1837 orig_request->flags.cachable << "; we_do_ranges: " << result);
1838
1839 return result;
1840 }
1841
1842 /* build request prefix and append it to a given MemBuf;
1843 * return the length of the prefix */
1844 mb_size_t
1845 HttpStateData::buildRequestPrefix(HttpRequest * request,
1846 HttpRequest * orig_request,
1847 StoreEntry * entry,
1848 MemBuf * mb,
1849 http_state_flags flags)
1850 {
1851 const int offset = mb->size;
1852 HttpVersion httpver(1, 0);
1853 mb->Printf("%s %s HTTP/%d.%d\r\n",
1854 RequestMethodStr(request->method),
1855 request->urlpath.size() ? request->urlpath.termedBuf() : "/",
1856 httpver.major,httpver.minor);
1857 /* build and pack headers */
1858 {
1859 HttpHeader hdr(hoRequest);
1860 Packer p;
1861 httpBuildRequestHeader(request, orig_request, entry, &hdr, flags);
1862
1863 if (request->flags.pinned && request->flags.connection_auth)
1864 request->flags.auth_sent = 1;
1865 else if (hdr.has(HDR_AUTHORIZATION))
1866 request->flags.auth_sent = 1;
1867
1868 packerToMemInit(&p, mb);
1869 hdr.packInto(&p);
1870 hdr.clean();
1871 packerClean(&p);
1872 }
1873 /* append header terminator */
1874 mb->append(crlf, 2);
1875 return mb->size - offset;
1876 }
1877
1878 /* This will be called when connect completes. Write request. */
1879 bool
1880 HttpStateData::sendRequest()
1881 {
1882 MemBuf mb;
1883
1884 debugs(11, 5, "httpSendRequest: FD " << fd << ", request " << request << ", this " << this << ".");
1885 typedef CommCbMemFunT<HttpStateData, CommTimeoutCbParams> TimeoutDialer;
1886 AsyncCall::Pointer timeoutCall = asyncCall(11, 5, "HttpStateData::httpTimeout",
1887 TimeoutDialer(this,&HttpStateData::httpTimeout));
1888 commSetTimeout(fd, Config.Timeout.lifetime, timeoutCall);
1889 flags.do_next_read = 1;
1890 maybeReadVirginBody();
1891
1892 if (orig_request->body_pipe != NULL) {
1893 if (!startRequestBodyFlow()) // register to receive body data
1894 return false;
1895 typedef CommCbMemFunT<HttpStateData, CommIoCbParams> Dialer;
1896 Dialer dialer(this, &HttpStateData::sentRequestBody);
1897 requestSender = asyncCall(11,5, "HttpStateData::sentRequestBody", dialer);
1898 } else {
1899 assert(!requestBodySource);
1900 typedef CommCbMemFunT<HttpStateData, CommIoCbParams> Dialer;
1901 Dialer dialer(this, &HttpStateData::sendComplete);
1902 requestSender = asyncCall(11,5, "HttpStateData::SendComplete", dialer);
1903 }
1904
1905 if (_peer != NULL) {
1906 if (_peer->options.originserver) {
1907 flags.proxying = 0;
1908 flags.originpeer = 1;
1909 } else {
1910 flags.proxying = 1;
1911 flags.originpeer = 0;
1912 }
1913 } else {
1914 flags.proxying = 0;
1915 flags.originpeer = 0;
1916 }
1917
1918 /*
1919 * Is keep-alive okay for all request methods?
1920 */
1921 if (orig_request->flags.must_keepalive)
1922 flags.keepalive = 1;
1923 else if (!Config.onoff.server_pconns)
1924 flags.keepalive = 0;
1925 else if (_peer == NULL)
1926 flags.keepalive = 1;
1927 else if (_peer->stats.n_keepalives_sent < 10)
1928 flags.keepalive = 1;
1929 else if ((double) _peer->stats.n_keepalives_recv /
1930 (double) _peer->stats.n_keepalives_sent > 0.50)
1931 flags.keepalive = 1;
1932
1933 if (_peer) {
1934 if (neighborType(_peer, request) == PEER_SIBLING &&
1935 !_peer->options.allow_miss)
1936 flags.only_if_cached = 1;
1937
1938 flags.front_end_https = _peer->front_end_https;
1939 }
1940
1941 mb.init();
1942 buildRequestPrefix(request, orig_request, entry, &mb, flags);
1943 debugs(11, 6, "httpSendRequest: FD " << fd << ":\n" << mb.buf);
1944 comm_write_mbuf(fd, &mb, requestSender);
1945
1946 return true;
1947 }
1948
1949 void
1950 httpStart(FwdState *fwd)
1951 {
1952 debugs(11, 3, "httpStart: \"" << RequestMethodStr(fwd->request->method) << " " << fwd->entry->url() << "\"" );
1953 HttpStateData *httpState = new HttpStateData(fwd);
1954
1955 if (!httpState->sendRequest()) {
1956 debugs(11, 3, "httpStart: aborted");
1957 delete httpState;
1958 return;
1959 }
1960
1961 statCounter.server.all.requests++;
1962 statCounter.server.http.requests++;
1963
1964 /*
1965 * We used to set the read timeout here, but not any more.
1966 * Now its set in httpSendComplete() after the full request,
1967 * including request body, has been written to the server.
1968 */
1969 }
1970
1971 void
1972 HttpStateData::doneSendingRequestBody()
1973 {
1974 debugs(11,5, HERE << "doneSendingRequestBody: FD " << fd);
1975
1976 #if HTTP_VIOLATIONS
1977 if (Config.accessList.brokenPosts) {
1978 ACLFilledChecklist ch(Config.accessList.brokenPosts, request, NULL);
1979 if (!ch.fastCheck()) {
1980 debugs(11, 5, "doneSendingRequestBody: didn't match brokenPosts");
1981 CommIoCbParams io(NULL);
1982 io.fd=fd;
1983 io.flag=COMM_OK;
1984 sendComplete(io);
1985 } else {
1986 debugs(11, 2, "doneSendingRequestBody: matched brokenPosts");
1987 typedef CommCbMemFunT<HttpStateData, CommIoCbParams> Dialer;
1988 Dialer dialer(this, &HttpStateData::sendComplete);
1989 AsyncCall::Pointer call= asyncCall(11,5, "HttpStateData::SendComplete", dialer);
1990 comm_write(fd, "\r\n", 2, call);
1991 }
1992 return;
1993 }
1994 debugs(11, 5, "doneSendingRequestBody: No brokenPosts list");
1995 #endif /* HTTP_VIOLATIONS */
1996
1997 CommIoCbParams io(NULL);
1998 io.fd=fd;
1999 io.flag=COMM_OK;
2000 sendComplete(io);
2001 }
2002
2003 // more origin request body data is available
2004 void
2005 HttpStateData::handleMoreRequestBodyAvailable()
2006 {
2007 if (eof || fd < 0) {
2008 // XXX: we should check this condition in other callbacks then!
2009 // TODO: Check whether this can actually happen: We should unsubscribe
2010 // as a body consumer when the above condition(s) are detected.
2011 debugs(11, 1, HERE << "Transaction aborted while reading HTTP body");
2012 return;
2013 }
2014
2015 assert(requestBodySource != NULL);
2016
2017 if (requestBodySource->buf().hasContent()) {
2018 // XXX: why does not this trigger a debug message on every request?
2019
2020 if (flags.headers_parsed && !flags.abuse_detected) {
2021 flags.abuse_detected = 1;
2022 debugs(11, 1, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << orig_request->client_addr << "' -> '" << entry->url() << "'" );
2023
2024 if (virginReply()->sline.status == HTTP_INVALID_HEADER) {
2025 comm_close(fd);
2026 return;
2027 }
2028 }
2029 }
2030
2031 HttpStateData::handleMoreRequestBodyAvailable();
2032 }
2033
2034 // premature end of the request body
2035 void
2036 HttpStateData::handleRequestBodyProducerAborted()
2037 {
2038 ServerStateData::handleRequestBodyProducerAborted();
2039 // XXX: SendComplete(COMM_ERR_CLOSING) does little. Is it enough?
2040 CommIoCbParams io(NULL);
2041 io.fd=fd;
2042 io.flag=COMM_ERR_CLOSING;
2043 sendComplete(io);
2044 }
2045
2046 // called when we wrote request headers(!) or a part of the body
2047 void
2048 HttpStateData::sentRequestBody(const CommIoCbParams &io)
2049 {
2050 if (io.size > 0)
2051 kb_incr(&statCounter.server.http.kbytes_out, io.size);
2052
2053 ServerStateData::sentRequestBody(io);
2054 }
2055
2056 // Quickly abort the transaction
2057 // TODO: destruction should be sufficient as the destructor should cleanup,
2058 // including canceling close handlers
2059 void
2060 HttpStateData::abortTransaction(const char *reason)
2061 {
2062 debugs(11,5, HERE << "aborting transaction for " << reason <<
2063 "; FD " << fd << ", this " << this);
2064
2065 if (fd >= 0) {
2066 comm_close(fd);
2067 return;
2068 }
2069
2070 fwd->handleUnregisteredServerEnd();
2071 deleteThis("HttpStateData::abortTransaction");
2072 }
2073
2074 #if DEAD_CODE
2075 void
2076 httpBuildVersion(HttpVersion * version, unsigned int major, unsigned int minor)
2077 {
2078 version->major = major;
2079 version->minor = minor;
2080 }
2081 #endif
2082
2083 HttpRequest *
2084 HttpStateData::originalRequest()
2085 {
2086 return orig_request;
2087 }