Kea 2.5.8
response_json.h
Go to the documentation of this file.
1// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef HTTP_RESPONSE_JSON_H
8#define HTTP_RESPONSE_JSON_H
9
10#include <cc/data.h>
12#include <http/response.h>
13
14namespace isc {
15namespace http {
16
19public:
20 HttpResponseJsonError(const char* file, size_t line, const char* what) :
21 HttpResponseError(file, line, what) { };
22};
23
24class HttpResponseJson;
25
27typedef boost::shared_ptr<HttpResponseJson> HttpResponseJsonPtr;
28
35public:
36
38 explicit HttpResponseJson();
39
49 explicit HttpResponseJson(const HttpVersion& version,
50 const HttpStatusCode& status_code,
51 const CallSetGenericBody& generic_body =
53
60 virtual void finalize();
61
63 virtual void reset();
64
70
75 void setBodyAsJson(const data::ConstElementPtr& json_body);
76
86 data::ConstElementPtr getJsonElement(const std::string& element_name) const;
87
88private:
89
99 void setGenericBody(const HttpStatusCode& status_code);
100
101protected:
102
105 void parseBodyAsJson();
106
109};
110
111} // end of namespace isc::http
112} // end of namespace isc
113
114#endif
int version()
returns Kea hooks version.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Generic exception thrown by HttpResponse class.
Definition: response.h:23
Exception thrown when body of the HTTP message is not JSON.
Definition: response_json.h:18
HttpResponseJsonError(const char *file, size_t line, const char *what)
Definition: response_json.h:20
Represents HTTP response with JSON content.
Definition: response_json.h:34
void setBodyAsJson(const data::ConstElementPtr &json_body)
Generates JSON content from the data structures represented as data::ConstElementPtr.
void parseBodyAsJson()
Interprets body as JSON, which can be later retrieved using data element objects.
data::ConstElementPtr json_
Pointer to the parsed JSON body.
HttpResponseJson()
Constructor for the inbound HTTP response.
virtual void finalize()
Completes creation of the HTTP response.
virtual void reset()
Reset the state of the object.
data::ConstElementPtr getJsonElement(const std::string &element_name) const
Retrieves a single JSON element.
data::ConstElementPtr getBodyAsJson() const
Retrieves JSON body.
Represents HTTP response message.
Definition: response.h:98
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
HttpStatusCode
HTTP status codes (cf RFC 2068)
Definition: response.h:30
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
Definition: response_json.h:27
Defines the logger used by the top-level component of kea-lfc.
Encapsulates the boolean value indicating if the HttpResponse constructor should call its setGenericB...
Definition: response.h:52
static const CallSetGenericBody & yes()
Returns encapsulated true.
Definition: response.h:63
HTTP protocol version.
Definition: http_types.h:14