af0f8e4f5e56ac0957a70824514a95e715a6610b
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * @defgroup request request
27 typedef struct request_t request_t
;
30 * A HTTP request, encapsulates FCGX_Request.
32 * The response is also handled through the request object.
37 * Add a cookie to the reply (Set-Cookie header).
39 * @param name name of the cookie to set
40 * @param value value of the cookie
42 void (*add_cookie
)(request_t
*this, char *name
, char *value
);
45 * Get a cookie the client sent in the request.
47 * @param name name of the cookie
48 * @return cookie value, NULL if no such cookie found
50 char* (*get_cookie
)(request_t
*this, char *name
);
53 * Get the request path relative to the application.
57 char* (*get_path
)(request_t
*this);
60 * Get the base path of the application.
64 char* (*get_base
)(request_t
*this);
67 * Get the remote host address of this request.
69 * @return host address as string
71 char* (*get_host
)(request_t
*this);
74 * Get the user agent string.
76 * @return user agent string
78 char* (*get_user_agent
)(request_t
*this);
81 * Get a post/get variable included in the request.
83 * @param name name of the POST/GET variable
84 * @return value, NULL if not found
86 char* (*get_query_data
)(request_t
*this, char *name
);
89 * Close the session and it's context after handling.
91 void (*close_session
)(request_t
*this);
94 * Has the session been closed by close_session()?
96 * @return TRUE if session has been closed
98 bool (*session_closed
)(request_t
*this);
101 * Redirect the client to another location.
103 * @param fmt location format string
104 * @param ... variable argument for fmt
106 void (*redirect
)(request_t
*this, char *fmt
, ...);
109 * Get the HTTP referer.
111 * @return HTTP referer
113 char* (*get_referer
)(request_t
*this);
116 * Redirect back to the referer.
118 void (*to_referer
)(request_t
*this);
121 * Set a template value.
123 * @param key key to set
124 * @param value value to set key to
126 void (*set
)(request_t
*this, char *key
, char *value
);
129 * Set a template value using format strings.
131 * Format string is in the form "key=value", where printf like format
132 * substitution occurs over the whole string.
134 * @param format printf like format string
135 * @param ... variable argument list
137 void (*setf
)(request_t
*this, char *format
, ...);
142 * The render() function additionally sets a HDF variable "base"
143 * which points to the root of the web application and allows to point to
144 * other targets without to worry about path location.
146 * @param template clearsilver template file location
148 void (*render
)(request_t
*this, char *template);
151 * Stream a format string to the client.
153 * Stream is not closed and may be called multiple times to allow
154 * server-push functionality.
156 * @param format printf like format string
157 * @param ... argmuent list to format string
158 * @return number of streamed bytes, < 0 if stream closed
160 int (*streamf
)(request_t
*this, char *format
, ...);
163 * Serve a request with headers and a body.
165 * @param headers HTTP headers, \n separated
166 * @param chunk body to write to output
168 void (*serve
)(request_t
*this, char *headers
, chunk_t chunk
);
171 * Increase the reference count to the stream.
173 * @return this with increased refcount
175 request_t
* (*get_ref
)(request_t
*this);
178 * Destroy the request_t.
180 void (*destroy
) (request_t
*this);
184 * Create a request from the fastcgi struct.
186 * @param fd file descripter opened with FCGX_OpenSocket
187 * @param debug no stripping, no compression, timing information
189 request_t
*request_create(int fd
, bool debug
);
191 #endif /** REQUEST_H_ @}*/