]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http/StatusLine.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / http / StatusLine.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_HTTP_STATUSLINE_H
10 #define SQUID_HTTP_STATUSLINE_H
11
12 #include "http/ProtocolVersion.h"
13 #include "http/StatusCode.h"
14 #include "SquidString.h"
15
16 class Packer;
17 class String;
18
19 namespace Http
20 {
21
22 /**
23 * Holds the values parsed from an HTTP reply status line.
24 *
25 * For example: HTTP/1.1 200 OK
26 */
27 class StatusLine
28 {
29 public:
30 /// reset this status-line back to empty state
31 void init();
32
33 /// reset this status-line back to Internal Server Error state
34 void clean();
35
36 /// set this status-line to the given values
37 /// when reason is NULL the default message text for this StatusCode will be used
38 void set(const Http::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason = NULL);
39
40 /// retrieve the status code for this status line
41 Http::StatusCode status() const { return status_; }
42
43 /// retrieve the reason string for this status line
44 const char *reason() const;
45
46 /// pack fields using Packer
47 void packInto(Packer * p) const;
48
49 /**
50 * Parse a buffer and fill internal structures;
51 * \return true on success, false otherwise
52 */
53 bool parse(const String &protoPrefix, const char *start, const char *end);
54
55 public:
56 /* public, read only */
57
58 /**
59 * By rights protocol name should be a constant "HTTP", with no need for this field to exist.
60 * However there are protocols which violate HTTP by sending their own custom formats
61 * back with other protocol names (ICY streaming format being the current major problem).
62 */
63 // XXX: protocol is part of Http::ProtocolVersion. We should be able to use version.protocol instead now.
64 AnyP::ProtocolType protocol;
65
66 Http::ProtocolVersion version; ///< breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
67
68 private:
69 /// status code. ie 100 ... 200 ... 404 ... 599
70 Http::StatusCode status_;
71
72 /// points to a _constant_ string (default or supplied), never free()d
73 const char *reason_;
74 };
75
76 } // namespace Http
77
78 #endif /* SQUID_HTTP_STATUSLINE_H */