]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http/StatusLine.h
9facda86781582e2cd2c1aeb4afe90e423ef410c
[thirdparty/squid.git] / src / http / StatusLine.h
1 /*
2 * Copyright (C) 1996-2019 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 Packable;
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 /// when reason is not NULL, it must not point to a dynamically allocated value
39 void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason = NULL);
40
41 /// reset the reason phrase to its default status code-derived value
42 void resetReason() { reason_ = nullptr; }
43
44 /// retrieve the status code for this status line
45 Http::StatusCode status() const { return status_; }
46
47 /// retrieve the reason string for this status line
48 const char *reason() const;
49
50 /// pack fields into a Packable object
51 void packInto(Packable *) const;
52
53 /**
54 * Parse a buffer and fill internal structures;
55 * \return true on success, false otherwise
56 */
57 bool parse(const String &protoPrefix, const char *start, const char *end);
58
59 public:
60 /* public, read only */
61
62 /**
63 * By rights protocol name should be a constant "HTTP", with no need for this field to exist.
64 * However there are protocols which violate HTTP by sending their own custom formats
65 * back with other protocol names (ICY streaming format being the current major problem).
66 */
67 // XXX: protocol is part of AnyP::ProtocolVersion. We should be able to use version.protocol instead now.
68 AnyP::ProtocolType protocol;
69
70 AnyP::ProtocolVersion version; ///< breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
71
72 private:
73 /// status code. ie 100 ... 200 ... 404 ... 599
74 Http::StatusCode status_;
75
76 /// points to a _constant_ string (default or supplied), never free()d
77 const char *reason_;
78 };
79
80 } // namespace Http
81
82 #endif /* SQUID_HTTP_STATUSLINE_H */
83