]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
When serving dynamic content, include a Cache-Control header to instruct the
authorRussell Bryant <russell@russellbryant.com>
Mon, 30 Apr 2007 15:25:31 +0000 (15:25 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 30 Apr 2007 15:25:31 +0000 (15:25 +0000)
browsers to not store the resulting content.
(issue #9621, reported by Pari, patch by me)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@62414 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/http.h
main/http.c

index 055116324b4ba06af765fc00857467a13231b58d..ba6f094e432f8607281376f36b18c2df15780658 100644 (file)
@@ -42,7 +42,9 @@ struct ast_http_uri {
        struct ast_http_uri *next;
        const char *description;
        const char *uri;
-       int has_subtree;
+       unsigned int has_subtree:1;
+       /*! This URI mapping serves static content */
+       unsigned int static_content:1;
        ast_http_callback callback;
 };
 
index 9c0919a78d1af00a6febde1e9ef48a9e68ea4891..662afb03ed74ca929c006ef0b3f355df27de3d7f 100644 (file)
@@ -225,6 +225,7 @@ static struct ast_http_uri staticuri = {
        .description = "Asterisk HTTP Static Delivery",
        .uri = "static",
        .has_subtree = 1,
+       .static_content = 1,
 };
        
 char *ast_http_error(int status, const char *title, const char *extra_header, const char *text)
@@ -291,7 +292,9 @@ void ast_http_uri_unlink(struct ast_http_uri *urih)
        ast_rwlock_unlock(&uris_lock);
 }
 
-static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength, struct ast_variable **cookies)
+static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, 
+       char **title, int *contentlength, struct ast_variable **cookies, 
+       unsigned int *static_content)
 {
        char *c;
        char *turi;
@@ -358,6 +361,8 @@ static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **
                }
        }
        if (urih) {
+               if (urih->static_content)
+                       *static_content = 1;
                c = urih->callback(sin, uri, vars, status, title, contentlength);
                ast_rwlock_unlock(&uris_lock);
        } else if (ast_strlen_zero(uri) && ast_strlen_zero(prefix)) {
@@ -385,6 +390,7 @@ static void *ast_httpd_helper_thread(void *data)
        char *vname, *vval;
        int status = 200, contentlength = 0;
        time_t t;
+       unsigned int static_content = 0;
 
        if (fgets(buf, sizeof(buf), ser->f)) {
                /* Skip method */
@@ -468,7 +474,7 @@ static void *ast_httpd_helper_thread(void *data)
 
                if (*uri) {
                        if (!strcasecmp(buf, "get")) 
-                               c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars);
+                               c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars, &static_content);
                        else 
                                c = ast_http_error(501, "Not Implemented", NULL, "Attempt to use unimplemented / unsupported method");\
                } else 
@@ -487,6 +493,8 @@ static void *ast_httpd_helper_thread(void *data)
                        ast_cli(ser->fd, "Server: Asterisk/%s\r\n", ASTERISK_VERSION);
                        ast_cli(ser->fd, "Date: %s\r\n", timebuf);
                        ast_cli(ser->fd, "Connection: close\r\n");
+                       if (!static_content)
+                               ast_cli(ser->fd, "Cache-Control: no-cache, no-store\r\n");
                        if (contentlength) {
                                char *tmp;
                                tmp = strstr(c, "\r\n\r\n");