]>
Commit | Line | Data |
---|---|---|
450e0c10 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
450e0c10 | 3 | * |
bbc27441 AJ |
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. | |
450e0c10 | 7 | */ |
bbc27441 | 8 | |
9b769c67 AJ |
9 | #ifndef SQUID_HTTP_STATUSLINE_H |
10 | #define SQUID_HTTP_STATUSLINE_H | |
450e0c10 | 11 | |
526ed14e | 12 | #include "http/ProtocolVersion.h" |
955394ce | 13 | #include "http/StatusCode.h" |
e77d7ef0 | 14 | #include "SquidString.h" |
450e0c10 | 15 | |
17802cf1 | 16 | class Packable; |
955394ce AJ |
17 | class String; |
18 | ||
9b769c67 AJ |
19 | namespace Http |
20 | { | |
21 | ||
e77d7ef0 AJ |
22 | /** |
23 | * Holds the values parsed from an HTTP reply status line. | |
24 | * | |
9b769c67 | 25 | * For example: HTTP/1.1 200 OK |
e77d7ef0 | 26 | */ |
9b769c67 | 27 | class StatusLine |
450e0c10 | 28 | { |
9b769c67 AJ |
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 | |
65b0aca4 | 38 | /// when reason is not NULL, it must not point to a dynamically allocated value |
2592bc70 | 39 | void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason = NULL); |
9b769c67 | 40 | |
65b0aca4 AR |
41 | /// reset the reason phrase to its default status code-derived value |
42 | void resetReason() { reason_ = nullptr; } | |
43 | ||
9b769c67 | 44 | /// retrieve the status code for this status line |
e3b44909 | 45 | Http::StatusCode status() const { return status_; } |
9b769c67 AJ |
46 | |
47 | /// retrieve the reason string for this status line | |
48 | const char *reason() const; | |
49 | ||
0a647ffb AJ |
50 | /// pack fields into a Packable object |
51 | void packInto(Packable *) const; | |
9b769c67 AJ |
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 | ||
450e0c10 | 59 | public: |
60 | /* public, read only */ | |
e77d7ef0 AJ |
61 | |
62 | /** | |
63 | * By rights protocol name should be a constant "HTTP", with no need for this field to exist. | |
0c3d3f65 AJ |
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). | |
e77d7ef0 | 66 | */ |
2592bc70 | 67 | // XXX: protocol is part of AnyP::ProtocolVersion. We should be able to use version.protocol instead now. |
0c3d3f65 | 68 | AnyP::ProtocolType protocol; |
e77d7ef0 | 69 | |
2592bc70 | 70 | AnyP::ProtocolVersion version; ///< breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1) |
9b769c67 AJ |
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_; | |
450e0c10 | 78 | }; |
79 | ||
9b769c67 AJ |
80 | } // namespace Http |
81 | ||
82 | #endif /* SQUID_HTTP_STATUSLINE_H */ | |
f53969cc | 83 |