1
// ---------------------------------------------------------------------------
3
// - afnix:nwg module - http reply class definition -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2007 amaury darsch -
15
// ---------------------------------------------------------------------------
17
#ifndef AFNIX_HTTPREPLY_HPP
18
#define AFNIX_HTTPREPLY_HPP
20
#ifndef AFNIX_MIME_HPP
24
#ifndef AFNIX_COOKIE_HPP
28
#ifndef AFNIX_HTTPPROTO_HPP
29
#include "HttpProto.hpp"
34
/// The HttpReply class is a simple designed to format a http reply.
35
/// When the write method is called, the header and the buffer are
36
/// formatted to the output stream argument. The class creates initially
37
/// the 'content-type' property which is initialized to the 'text/plain'
38
/// mime value. The object can also be filled with a mime document. This
39
/// kind of reply is usefull when responding to cgi request. In that case,
40
/// the content-type is changed according to the mime document type.
41
/// @author amaury darsch
43
class HttpReply : public HttpProto {
49
/// create an empty http reply
52
/// create an empty reply with a content type
53
/// @param type the content type to use
54
HttpReply (const String& type);
56
/// @return the class name
57
String repr (void) const;
59
/// set a cookie in the header
60
/// @param cook the cookie to set
61
virtual void setcook (const Cookie& cook);
63
/// add a string to the http buffer
64
/// @param lval the literal value to add
65
virtual void addhbuf (const Literal& lval);
67
/// add a buffer content to the http buffer
68
/// @param buf the buffer to add
69
virtual void addhbuf (const Buffer& buf);
71
/// add a mime document to the http buffer
72
/// @param mime the document to add
73
virtual void addhbuf (const Mime& mime);
75
/// set the hhtp reply status code
76
/// @param code the http status code
77
virtual void setstatus (const long code);
79
/// reply a redirect status with a url
80
/// @param url the target url
81
virtual void redirect (const String& url);
83
/// write the http reply to an output stream
84
/// @param os the output stream
85
void write (Output& os) const;
87
/// write the http reply to a buffer
88
/// @param buf the target buffer
89
void write (Buffer& buf) const;
92
// make the copy constructor private
93
HttpReply (const HttpReply&);
94
// make the assignment operator private
95
HttpReply& operator = (const HttpReply&);
98
/// create a new object in a generic object
99
/// @param argv the argument vector
100
static Object* mknew (Vector* argv);
102
/// @return true if the given quark is defined
103
bool isquark (const long quark, const bool hflg) const;
105
/// apply this object with a set of arguments and a quark
106
/// @param robj the current runnable
107
/// @param nset the current nameset
108
/// @param quark the quark to apply these arguments
109
/// @param argv the arguments to apply
110
Object* apply (Runnable* robj, Nameset* nset, const long quark,