]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http/StatusLine.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / http / StatusLine.h
CommitLineData
450e0c10 1/*
b8ae064d 2 * Copyright (C) 1996-2023 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 16class Packable;
955394ce
AJ
17class String;
18
9b769c67
AJ
19namespace Http
20{
21
e77d7ef0 22/**
8774ca07 23 * Holds the values parsed from an HTTP-like reply status line.
e77d7ef0 24 *
9b769c67 25 * For example: HTTP/1.1 200 OK
e77d7ef0 26 */
9b769c67 27class StatusLine
450e0c10 28{
9b769c67
AJ
29public:
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
aee3523a 39 void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason = nullptr);
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 59public:
60 /* public, read only */
e77d7ef0 61
2592bc70 62 AnyP::ProtocolVersion version; ///< breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
9b769c67
AJ
63
64private:
65 /// status code. ie 100 ... 200 ... 404 ... 599
8774ca07 66 Http::StatusCode status_ = scNone;
9b769c67
AJ
67
68 /// points to a _constant_ string (default or supplied), never free()d
8774ca07 69 const char *reason_ = nullptr;
450e0c10 70};
71
9b769c67
AJ
72} // namespace Http
73
74#endif /* SQUID_HTTP_STATUSLINE_H */
f53969cc 75