Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:55:13+00:00 2026-06-05T19:55:13+00:00

I made a simple module for Lighttpd to experiment with it. If I just

  • 0

I made a simple module for Lighttpd to experiment with it. If I just log on to the Ip address of my computer(from another computer) and the webserver(lighttpd) in my computer should send a simple response. The source code of the module is as below:

#include "base.h"
#include "log.h"
#include "buffer.h"
#include <stdio.h>
#include "plugin.h"
#include<sys/stat.h>
#include<sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "stat_cache.h"
#include "etag.h"
#include "http_chunk.h"
#include "response.h"
/* plugin config for all request/connections */


typedef struct {
    array *match;
} plugin_config;



typedef struct {
    PLUGIN_DATA;

    buffer *match_buf;

    plugin_config **config_storage;

    plugin_config conf;
} plugin_data;



typedef struct {
    size_t foo;
} handler_ctx;



static handler_ctx * handler_ctx_init() {
    handler_ctx * hctx;

    hctx = calloc(1, sizeof(*hctx));

    return hctx;
}



static void handler_ctx_free(handler_ctx *hctx) {

    free(hctx);
}

/* init the plugin data */
INIT_FUNC(mod_helloworld_init) {
    plugin_data *p;

    p = calloc(1, sizeof(*p));

    p->match_buf = buffer_init();

    return p;
}



/* detroy the plugin data */
FREE_FUNC(mod_helloworld_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 (!s) continue;

            array_free(s->match);

            free(s);
        }
        free(p->config_storage);
    }

    buffer_free(p->match_buf);

    free(p);

    return HANDLER_GO_ON;
}



/* handle plugin config and check values */

SETDEFAULTS_FUNC(mod_helloworld_set_defaults) {
    plugin_data *p = p_d;
    size_t i = 0;

    config_values_t cv[] = {
    { "helloworld.array",NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION},       /* 0 */
    { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
    };

    if (!p) return HANDLER_ERROR;

    p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));

    for (i = 0; i < srv->config_context->used; i++) {
        plugin_config *s;

        s = calloc(1, sizeof(plugin_config));
        s->match    = array_init();

        cv[0].destination = s->match;

        p->config_storage[i] = s;

        if (0 != config_insert_values_global(srv, ((data_config*)srv->config_context->data[i])->value, cv)) {
            return HANDLER_ERROR;
        }
    }

    return HANDLER_GO_ON;
}

#define PATCH(x) \
    p->conf.x = s->x;
static int mod_helloworld_patch_connection(server *srv, connection *con, plugin_data *p) {
    size_t i, j;
    plugin_config *s = p->config_storage[0];

    PATCH(match);

    /* skip the first, the global context */
    for (i = 1; i < srv->config_context->used; i++) {
        data_config *dc = (data_config *)srv->config_context->data[i];
        s = p->config_storage[i];

        /* condition didn't match */
        if (!config_check_cond(srv, con, dc)) continue;

        /* merge config */
        for (j = 0; j < dc->value->used; j++) {
            data_unset *du = dc->value->data[j];

            if (buffer_is_equal_string(du->key, CONST_STR_LEN("helloworld.array"))) {
                PATCH(match);
            }
        }
    }

    return 0;
}
#undef PATCH

URIHANDLER_FUNC(mod_helloworld_uri_handler) {


UNUSED(p_d);

// Send body data to requestor
char buffer[] = { '<', 'h', 't', 'm', 'l', '>' , '<', 'h', 'e', 'a', 'd', '>', '<', 't', 'i', 't', 'l', 'e', '>', '1', '<', '/', 't', 'i', 't', 'l', 'e', '>', '<', '/', 'h', 'e', 'a', 'd', '>', '<', '/', 'h', 't', 'm', 'l', '>'};

    char textValue[32];
    sprintf(textValue, "%d", sizeof(buffer));

response_header_overwrite(srv, con, CONST_STR_LEN("Content-Length"), textValue, strlen(textValue));
chunkqueue_append_mem(con->write_queue, buffer, sizeof(buffer)); 

//
con->http_status = 200;
return HANDLER_FINISHED;

}


int mod_helloworld_plugin_init(plugin *p) {
    p->version     = LIGHTTPD_VERSION_ID;
    p->name        = buffer_init_string("helloworld");

    p->init        = mod_helloworld_init;
    p->handle_subrequest_start  = mod_helloworld_uri_handler;
    p->set_defaults  = mod_helloworld_set_defaults;
    p->cleanup     = mod_helloworld_free;

    p->data        = NULL;

    return 0;
}

By using this module the web server should response with html page whose title is “1”. But now I see that lighttpd is sending that respond very late, and as a result the request is sometimes timed out. I am not quite getting what’s the problem. Could any body check and help me solve it? I guess only the users of Lighttpd may know the solution to this problem. Even without using Lighttpd if some one can help me solve this I’d appreciate that. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:55:15+00:00Added an answer on June 5, 2026 at 7:55 pm

    Try adding:

    con->file_finished = 1;
    

    after:

    con->http_status = 200;
    

    That tells the engine that the request is complete (why HANDLER_FINISHED doesn’t do that is a question for another day).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This module is part of a simple todo app I made with Python... def
I made simple email in wordpress but it would only send email to the
so I'm making some basic programming language (just for exercise). I've made simple grammar
Using orchard 1.3.9 I made a simple HelloWorld module. That module has a reference
I made a simple program for my friends using some things from the os
hi I've made a simple module with CTLModuleMaker in CMS made simple, in the
I have made a simple realtime visitor counter. You can download it from this
Visual Studio 2008 (vb.net) I made simple anivirus but when I make Full scan
On Windows, testing different OSes is made simple using VMs. Is there a simple
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.