Changeset c3353ae5 in rtems


Ignore:
Timestamp:
Mar 8, 2018, 4:12:30 AM (14 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11
Children:
d4165e71
Parents:
7093cb5e
git-author:
Chris Johns <chrisj@…> (03/08/18 04:12:30)
git-committer:
Chris Johns <chrisj@…> (03/08/18 04:34:15)
Message:

cpukit/mttpd: Add a callback to generate a per file HTTP etag.

Closes #3324

Location:
cpukit/mghttpd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/mghttpd/mongoose.c

    r7093cb5e rc3353ae5  
    29902990}
    29912991
    2992 static void construct_etag(char *buf, size_t buf_len,
     2992static void construct_etag(const struct mg_connection *conn, const char *path,
     2993                           char *buf, size_t buf_len,
    29932994                           const struct file *filep) {
    2994   snprintf(buf, buf_len, "\"%lx.%" INT64_FMT "\"",
    2995            (unsigned long) filep->modification_time, filep->size);
     2995  if (conn->ctx->callbacks.http_etag != NULL &&
     2996      conn->ctx->callbacks.http_etag(conn, path, buf, buf_len)) {
     2997  }
     2998  else {
     2999    snprintf(buf, buf_len, "\"%lx.%" INT64_FMT "\"",
     3000             (unsigned long) filep->modification_time, filep->size);
     3001  }
    29963002}
    29973003
     
    30623068  gmt_time_string(date, sizeof(date), &curtime);
    30633069  gmt_time_string(lm, sizeof(lm), &filep->modification_time);
    3064   construct_etag(etag, sizeof(etag), filep);
     3070  construct_etag(conn, path, etag, sizeof(etag), filep);
    30653071
    30663072  (void) mg_printf(conn,
     
    32223228// Return True if we should reply 304 Not Modified.
    32233229static int is_not_modified(const struct mg_connection *conn,
     3230                           const char *path,
    32243231                           const struct file *filep) {
    32253232  char etag[64];
    32263233  const char *ims = mg_get_header(conn, "If-Modified-Since");
    32273234  const char *inm = mg_get_header(conn, "If-None-Match");
    3228   construct_etag(etag, sizeof(etag), filep);
     3235  construct_etag(conn, path, etag, sizeof(etag), filep);
    32293236  return (inm != NULL && !mg_strcasecmp(etag, inm)) ||
    32303237    (ims != NULL && filep->modification_time <= parse_date_string(ims));
     
    45924599                          path) > 0) {
    45934600    handle_ssi_file_request(conn, path);
    4594   } else if (is_not_modified(conn, &file)) {
     4601  } else if (is_not_modified(conn, path, &file)) {
    45954602    send_http_error(conn, 304, "Not Modified", "%s", "");
    45964603  } else {
  • cpukit/mghttpd/mongoose.h

    r7093cb5e rc3353ae5  
    125125  //   status: HTTP error status code.
    126126  int  (*http_error)(struct mg_connection *, int status);
     127
     128  // Called when mongoose needs to generate an HTTP etag.
     129  // Implementing this callback allows a custom etag to be generated. If
     130  // not implemented the standard etag generator is used which is the
     131  // modification time as a hex value and the file size.
     132  // Use this callback if the modification time cannot be controlled.
     133  // Parameters:
     134  //   path: path to the file being requested
     135  //   etag: buffer to write the etag into
     136  //   etag_len: the length of the etag buffer
     137  // Return value:
     138  int  (*http_etag)(const struct mg_connection *,
     139                    const char *path, char *etag, size_t etag_len);
    127140};
    128141
Note: See TracChangeset for help on using the changeset viewer.