/usr/include/aseba/switches/http2/HttpResponse.h is in aseba 1.6.0-3.1~build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | /*
Aseba - an event-based framework for distributed robot control
Copyright (C) 2007--2016:
Stephane Magnenat <stephane at magnenat dot net>
(http://stephane.magnenat.net)
and other contributors, see authors.txt for details
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASEBA_HTTP_RESPONSE
#define ASEBA_HTTP_RESPONSE
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include <dashel/dashel.h>
#include "HttpRequest.h"
namespace Aseba { namespace Http
{
/**
* Represents HTTP responses being sent as a reply to incoming HTTP requests.
*/
class HttpResponse
{
public:
typedef enum {
HTTP_STATUS_OK = 200,
HTTP_STATUS_CREATED = 201,
HTTP_STATUS_BAD_REQUEST = 400,
HTTP_STATUS_FORBIDDEN = 403,
HTTP_STATUS_NOT_FOUND = 404,
HTTP_STATUS_REQUEST_TIMEOUT = 408,
HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
HTTP_STATUS_NOT_IMPLEMENTED = 501,
HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
} HttpStatus;
HttpResponse(const HttpRequest *originatingRequest);
virtual ~HttpResponse();
/**
* Sends the HTTP response using the output method defined in an inheriting class.
*/
virtual void send();
virtual const HttpRequest *getOriginatingRequest() const { return originatingRequest; }
virtual void setVerbose(bool verbose) { this->verbose = verbose; }
virtual void setStatus(HttpStatus status) { this->status = status; }
virtual HttpStatus getStatus() const { return status; }
virtual void setHeader(const std::string& header, const std::string& value) { headers[header] = value; }
virtual const std::map<std::string, std::string>& getHeaders() const { return headers; }
virtual void setContent(const std::string& content) { this->content = content; }
virtual const std::string& getContent() const { return content; }
std::string getHeader(const std::string& header) const {
std::map<std::string, std::string>::const_iterator query = headers.find(header);
if(query != headers.end()) {
return query->second;
} else {
return "";
}
}
protected:
virtual void addStatusReply(std::ostringstream& reply);
virtual void addHeadersReply(std::ostringstream& reply);
virtual void writeRaw(const char *buffer, int length) = 0;
private:
const HttpRequest *originatingRequest;
bool verbose;
HttpStatus status;
std::map<std::string, std::string> headers;
std::string content;
};
class DashelHttpResponse : public HttpResponse
{
public:
DashelHttpResponse(DashelHttpRequest *originatingRequest) :
HttpResponse(originatingRequest),
stream(originatingRequest->getStream())
{
}
virtual ~DashelHttpResponse() {}
protected:
virtual void writeRaw(const char *buffer, int length)
{
stream->write(buffer, length);
stream->flush();
}
private:
Dashel::Stream *stream;
};
} }
#endif
|