Book Image

Lighttpd

By : Andre Bogus
Book Image

Lighttpd

By: Andre Bogus

Overview of this book

Table of Contents (20 chapters)
Lighttpd
Credits
About the Author
About the Reviewer
Preface
HTTP Status Codes

Rewriting the Request


As we can get the URL of our connection easily, it is a small step to change it. For example, we could want to add a random number to the filename to facilitate random image loading (apparently still quite a popular task). To make the task easy for us, we will add the number to the physical path after the URL has been parsed, not to disrupt the MIME type handling:

#include <stdlib.h>
#include "buffer.h"
#include "base.h"
#include "plugin.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
typedef struct {
unsigned int max;
} plugin_config;
typedef struct {
PLUGIN_DATA;
plugin_config **config_storage;
plugin_config conf;
} plugin_data;
INIT_FUNC(mod_random_init) {
plugin_data *p;
UNUSED(srv);
p = calloc(1, sizeof(*p));
return p;
}
FREE_FUNC(mod_random_free) {
plugin_data *p = p_d;
UNUSED(srv);
if (!p) return HANDLER_GO_ON;
if (p->config_storage) {
size_t i;
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s = p->config_storage[i];
if...