3 * $Id: HttpStatusLine.cc,v 1.22 2001/01/12 00:37:14 wessels Exp $
5 * DEBUG: section 57 HTTP Status-line
6 * AUTHOR: Alex Rousskov
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
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.
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.
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.
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.
40 const char *HttpStatusLineFormat
= "HTTP/%d.%d %3d %s\r\n";
43 httpStatusLineInit(HttpStatusLine
* sline
)
45 http_version_t version
;
46 httpBuildVersion(&version
, 0, 0);
47 httpStatusLineSet(sline
, version
, HTTP_STATUS_NONE
, NULL
);
51 httpStatusLineClean(HttpStatusLine
* sline
)
53 http_version_t version
;
54 httpBuildVersion(&version
, 0, 0);
55 httpStatusLineSet(sline
, version
, HTTP_INTERNAL_SERVER_ERROR
, NULL
);
60 httpStatusLineSet(HttpStatusLine
* sline
, http_version_t version
, http_status status
, const char *reason
)
63 sline
->version
= version
;
64 sline
->status
= status
;
65 /* Note: no xstrdup for 'reason', assumes constant 'reasons' */
66 sline
->reason
= reason
;
69 /* parse a 0-terminating buffer and fill internal structures; returns true on success */
71 httpStatusLinePackInto(const HttpStatusLine
* sline
, Packer
* p
)
74 debug(57, 9) ("packing sline %p using %p:\n", sline
, p
);
75 debug(57, 9) (HttpStatusLineFormat
, sline
->version
.major
,
76 sline
->version
.minor
, sline
->status
,
77 sline
->reason
? sline
->reason
: httpStatusString(sline
->status
));
78 packerPrintf(p
, HttpStatusLineFormat
, sline
->version
.major
,
79 sline
->version
.minor
, sline
->status
, httpStatusLineReason(sline
));
82 /* pack fields using Packer */
84 httpStatusLineParse(HttpStatusLine
* sline
, const char *start
, const char *end
)
87 sline
->status
= HTTP_INVALID_HEADER
; /* Squid header parsing error */
88 if (strncasecmp(start
, "HTTP/", 5))
91 if (!xisdigit(*start
))
93 if (sscanf(start
, "%d.%d", &sline
->version
.major
, &sline
->version
.minor
) != 2) {
94 debug(57, 7) ("httpStatusLineParse: Invalid HTTP identifier.\n");
96 if (!(start
= strchr(start
, ' ')))
98 sline
->status
= atoi(++start
);
99 /* we ignore 'reason-phrase' */
100 return 1; /* success */
104 httpStatusLineReason(const HttpStatusLine
* sline
)
107 return sline
->reason
? sline
->reason
: httpStatusString(sline
->status
);
111 httpStatusString(http_status status
)
113 /* why not to return matching string instead of using "p" ? @?@ */
114 const char *p
= NULL
;
117 p
= "Init"; /* we init .status with code 0 */
122 case HTTP_SWITCHING_PROTOCOLS
:
123 p
= "Switching Protocols";
134 case HTTP_NON_AUTHORITATIVE_INFORMATION
:
135 p
= "Non-Authoritative Information";
137 case HTTP_NO_CONTENT
:
140 case HTTP_RESET_CONTENT
:
143 case HTTP_PARTIAL_CONTENT
:
144 p
= "Partial Content";
146 case HTTP_MULTIPLE_CHOICES
:
147 p
= "Multiple Choices";
149 case HTTP_MOVED_PERMANENTLY
:
150 p
= "Moved Permanently";
152 case HTTP_MOVED_TEMPORARILY
:
153 p
= "Moved Temporarily";
158 case HTTP_NOT_MODIFIED
:
164 case HTTP_BAD_REQUEST
:
167 case HTTP_UNAUTHORIZED
:
170 case HTTP_PAYMENT_REQUIRED
:
171 p
= "Payment Required";
179 case HTTP_METHOD_NOT_ALLOWED
:
180 p
= "Method Not Allowed";
182 case HTTP_NOT_ACCEPTABLE
:
183 p
= "Not Acceptable";
185 case HTTP_PROXY_AUTHENTICATION_REQUIRED
:
186 p
= "Proxy Authentication Required";
188 case HTTP_REQUEST_TIMEOUT
:
189 p
= "Request Time-out";
197 case HTTP_LENGTH_REQUIRED
:
198 p
= "Length Required";
200 case HTTP_PRECONDITION_FAILED
:
201 p
= "Precondition Failed";
203 case HTTP_REQUEST_ENTITY_TOO_LARGE
:
204 p
= "Request Entity Too Large";
206 case HTTP_REQUEST_URI_TOO_LARGE
:
207 p
= "Request-URI Too Large";
209 case HTTP_UNSUPPORTED_MEDIA_TYPE
:
210 p
= "Unsupported Media Type";
212 case HTTP_INTERNAL_SERVER_ERROR
:
213 p
= "Internal Server Error";
215 case HTTP_NOT_IMPLEMENTED
:
216 p
= "Not Implemented";
218 case HTTP_BAD_GATEWAY
:
221 case HTTP_SERVICE_UNAVAILABLE
:
222 p
= "Service Unavailable";
224 case HTTP_GATEWAY_TIMEOUT
:
225 p
= "Gateway Time-out";
227 case HTTP_HTTP_VERSION_NOT_SUPPORTED
:
228 p
= "HTTP Version not supported";
232 debug(57, 3) ("Unknown HTTP status code: %d\n", status
);