]>
Commit | Line | Data |
---|---|---|
2246b732 | 1 | |
2 | /* | |
2b6662ba | 3 | * $Id: HttpMsg.cc,v 1.10 2001/01/12 00:37:14 wessels 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" | |
37 | ||
38 | ||
39 | /* find end of headers */ | |
40 | int | |
41 | httpMsgIsolateHeaders(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; | |
2246b732 | 50 | if (end) { |
51 | *blk_start = *parse_start; | |
bdb1a5d5 | 52 | *blk_end = *parse_start + end - 1; |
53 | /* | |
54 | * leave blk_end pointing to the first character after the | |
55 | * first newline which terminates the headers | |
56 | */ | |
57 | assert(**blk_end == '\n'); | |
58 | while (*(*blk_end - 1) == '\r') | |
59 | (*blk_end)--; | |
60 | assert(*(*blk_end - 1) == '\n'); | |
61 | *parse_start += end; | |
2246b732 | 62 | return 1; |
63 | } | |
bdb1a5d5 | 64 | /* |
65 | * If we didn't find the end of headers, and parse_start does | |
66 | * NOT point to a CR or NL character, then return failure | |
67 | */ | |
68 | if (**parse_start != '\r' && **parse_start != '\n') | |
69 | return 0; /* failure */ | |
70 | /* | |
71 | * If we didn't find the end of headers, and parse_start does point | |
72 | * to an empty line, then we have empty headers. Skip all CR and | |
73 | * NL characters up to the first NL. Leave parse_start pointing at | |
74 | * the first character after the first NL. | |
75 | */ | |
76 | *blk_start = *parse_start; | |
77 | *blk_end = *blk_start; | |
a4295415 | 78 | for (nnl = 0; nnl == 0; (*parse_start)++) { |
bdb1a5d5 | 79 | if (**parse_start == '\r') |
80 | (void) 0; | |
81 | else if (**parse_start == '\n') | |
82 | nnl++; | |
83 | else | |
84 | break; | |
2246b732 | 85 | } |
bdb1a5d5 | 86 | return 1; |
2246b732 | 87 | } |
88 | ||
89 | /* returns true if connection should be "persistent" | |
90 | * after processing this message */ | |
91 | int | |
ccf44862 | 92 | httpMsgIsPersistent(http_version_t http_ver, const HttpHeader * hdr) |
2246b732 | 93 | { |
bffee5af | 94 | if ((http_ver.major >= 1) && (http_ver.minor >= 1)) { |
2246b732 | 95 | /* |
96 | * for modern versions of HTTP: persistent unless there is | |
97 | * a "Connection: close" header. | |
98 | */ | |
99 | return !httpHeaderHasConnDir(hdr, "close"); | |
100 | } else { | |
101 | /* | |
102 | * Persistent connections in Netscape 3.x are allegedly broken, | |
103 | * return false if it is a browser connection. If there is a | |
104 | * VIA header, then we assume this is NOT a browser connection. | |
105 | */ | |
106 | const char *agent = httpHeaderGetStr(hdr, HDR_USER_AGENT); | |
107 | if (agent && !httpHeaderHas(hdr, HDR_VIA)) { | |
108 | if (!strncasecmp(agent, "Mozilla/3.", 10)) | |
109 | return 0; | |
110 | if (!strncasecmp(agent, "Netscape/3.", 11)) | |
111 | return 0; | |
112 | } | |
113 | /* for old versions of HTTP: persistent if has "keep-alive" */ | |
114 | return httpHeaderHasConnDir(hdr, "keep-alive"); | |
115 | } | |
116 | } |