]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpMsg.cc
Bug #890: Various HTTP workarounds and minor corrections
[thirdparty/squid.git] / src / HttpMsg.cc
CommitLineData
2246b732 1
2/*
21b92762 3 * $Id: HttpMsg.cc,v 1.14 2005/03/06 21:08:13 serassio Exp $
2246b732 4 *
5 * DEBUG: section 74 HTTP Message
6 * AUTHOR: Alex Rousskov
7 *
2b6662ba 8 * SQUID Web Proxy Cache http://www.squid-cache.org/
e25c139f 9 * ----------------------------------------------------------
2246b732 10 *
2b6662ba 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.
2246b732 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
cbdec147 32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
e25c139f 33 *
2246b732 34 */
35
36#include "squid.h"
450e0c10 37#include "HttpVersion.h"
2246b732 38
39/* find end of headers */
40int
41httpMsgIsolateHeaders(const char **parse_start, const char **blk_start, const char **blk_end)
42{
bdb1a5d5 43 /*
44 * parse_start points to the first line of HTTP message *headers*,
45 * not including the request or status lines
46 */
47 size_t l = strlen(*parse_start);
48 size_t end = headersEnd(*parse_start, l);
49 int nnl;
62e76326 50
2246b732 51 if (end) {
62e76326 52 *blk_start = *parse_start;
53 *blk_end = *parse_start + end - 1;
54 /*
55 * leave blk_end pointing to the first character after the
56 * first newline which terminates the headers
57 */
58 assert(**blk_end == '\n');
59
60 while (*(*blk_end - 1) == '\r')
61 (*blk_end)--;
62
63 assert(*(*blk_end - 1) == '\n');
64
65 *parse_start += end;
66
67 return 1;
2246b732 68 }
62e76326 69
bdb1a5d5 70 /*
71 * If we didn't find the end of headers, and parse_start does
72 * NOT point to a CR or NL character, then return failure
73 */
74 if (**parse_start != '\r' && **parse_start != '\n')
62e76326 75 return 0; /* failure */
76
bdb1a5d5 77 /*
78 * If we didn't find the end of headers, and parse_start does point
79 * to an empty line, then we have empty headers. Skip all CR and
80 * NL characters up to the first NL. Leave parse_start pointing at
81 * the first character after the first NL.
82 */
83 *blk_start = *parse_start;
62e76326 84
bdb1a5d5 85 *blk_end = *blk_start;
62e76326 86
a4295415 87 for (nnl = 0; nnl == 0; (*parse_start)++) {
62e76326 88 if (**parse_start == '\r')
89 (void) 0;
90 else if (**parse_start == '\n')
91 nnl++;
92 else
93 break;
2246b732 94 }
62e76326 95
bdb1a5d5 96 return 1;
2246b732 97}
98
62e76326 99/* returns true if connection should be "persistent"
2246b732 100 * after processing this message */
101int
450e0c10 102httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr)
2246b732 103{
21b92762 104#if WHEN_SQUID_IS_NOT_HTTP1_1
105
bffee5af 106 if ((http_ver.major >= 1) && (http_ver.minor >= 1)) {
62e76326 107 /*
108 * for modern versions of HTTP: persistent unless there is
109 * a "Connection: close" header.
110 */
111 return !httpHeaderHasConnDir(hdr, "close");
2246b732 112 } else {
21b92762 113#else
114 {
115#endif
62e76326 116 /*
117 * Persistent connections in Netscape 3.x are allegedly broken,
118 * return false if it is a browser connection. If there is a
119 * VIA header, then we assume this is NOT a browser connection.
120 */
121 const char *agent = httpHeaderGetStr(hdr, HDR_USER_AGENT);
122
21b92762 123 if (agent && !httpHeaderHas(hdr, HDR_VIA))
124 {
62e76326 125 if (!strncasecmp(agent, "Mozilla/3.", 10))
126 return 0;
127
128 if (!strncasecmp(agent, "Netscape/3.", 11))
129 return 0;
130 }
131
132 /* for old versions of HTTP: persistent if has "keep-alive" */
133 return httpHeaderHasConnDir(hdr, "keep-alive");
2246b732 134 }
135}