Ticket #768 (new enhancement)

Opened 2 years ago

Last modified 2 months ago

mod_cml - output_expires

Reported by: duke.amix@gmail.com Assigned to: jan
Priority: normal Milestone:
Component: mod_cml Version: 1.4.11
Severity: normal Keywords:
Cc: Blocking:
Need Feedback:

Description (Last modified by moo)

I use lighttpd-1.4.11 in production with mod_cml.

I needed to set the "Expires" from lua on some pages so i coded it. After about a month of use i thought maybe you would be interested in adding this feature.

Lua Programming: output_expires = <num>

mod_cml_lua.c:

(i added this right after the code with "output_contenttype")

/* get the expires from lua in seconds and generate the appropriate
 * response. values are in seconds (offset) from current time.
 */
        if (0 == lua_to_c_get_string(L, "output_expires", b)) {
                char timebuf[sizeof("Thu, 09 May 1985 13:13:13 GMT")];
                char *err;
                int num;
                time_t t = 0;
                size_t len;
                buffer *cc = buffer_init(); /* cc = cache-control */

                /* get the value from lua to an integer */
                num = strtol(b->ptr, &err, 10);

                if (*err != NULL) {
                        log_error_write(srv, __FILE__, __LINE__, "s",
                                "outout_expires not a valid <num>", b);
                        return HANDLER_ERROR;
                }

                /* current time + offset */
                time(&t);
                t += num;

                if (0 == (len = strftime(timebuf, sizeof(timebuf),
                        "%a, %d %b %Y %H:%M:%S GMT", gmtime(&(t))))) {
                                /* could not set expire header, out of mem */

                        return HANDLER_GO_ON;
                }

                /* HTTP/1.0 */
                response_header_overwrite(srv, con, CONST_STR_LEN("Expires"), timebuf, sizeof(timebuf) - 1);

                /* HTTP/1.1 */
                if (num != 0) {
                        buffer_copy_string_len(cc, "max-age=", 8);
                        buffer_append_string(cc, b->ptr);
                } else
                        buffer_copy_string_len(cc, "no-cache", 8);
                buffer_append_string_len(cc, ", must-revalidate", 17);
                response_header_overwrite(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(cc));

                buffer_free(cc);
        }

I have added the "must-revalidate" because i needed it, but you can just comment it out.

I use lighttpd-1.4.11 release (no - svn).

thanks,

-- amix.

Attachments

Change History

07/27/2006 01:14:14 AM changed by moo

  • description changed.

Add/Change #768 (mod_cml - output_expires)




Change Properties