Changeset 148

Show
Ignore:
Timestamp:
02/18/06 20:12:06 (3 years ago)
Author:
conrad
Message:

add support for If-Modified-Since

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fastphoto/trunk/src/cgi.c

    r147 r148  
    88#include "cache.h" 
    99#include "header.h" 
     10#include "httpdate.h" 
    1011#include "photo.h" 
    1112 
     
    7778  char * path_translated; 
    7879  char * query_string; 
     80  char * if_modified_since; 
     81  time_t since_time; 
    7982 
    8083  gateway_interface = getenv ("GATEWAY_INTERFACE"); 
     
    8386  } 
    8487 
     88  httpdate_init (); 
     89 
    8590  path_info = getenv ("PATH_INFO"); 
    8691  path_translated = getenv ("PATH_TRANSLATED"); 
    8792  query_string = getenv ("QUERY_STRING"); 
     93  if_modified_since = getenv ("HTTP_IF_MODIFIED_SINCE"); 
    8894 
    8995  photo_init (&params->in, path_translated); 
     96 
     97  if (if_modified_since != NULL) { 
     98    int len; 
     99 
     100    fprintf (stderr, "If-Modified-Since: %s\n", if_modified_since); 
     101 
     102    len = strlen (if_modified_since) + 1; 
     103    since_time = httpdate_parse (if_modified_since, len); 
     104 
     105    if (params->in.mtime <= since_time) { 
     106      return HTTP_NOT_MODIFIED; 
     107    } 
     108  } 
    90109 
    91110  parse_query (params, query_string); 
  • fastphoto/trunk/src/fastphoto.h

    r147 r148  
    88 
    99#define FASTPHOTO_DEFAULT_CACHEDIR "/var/cache/fastphoto" 
     10 
     11#define HTTP_NOT_MODIFIED 304 
    1012 
    1113typedef struct fastphoto_s fastphoto_t; 
  • fastphoto/trunk/src/header.c

    r143 r148  
    1616  httpdate_snprint (buf, 30, mtime); 
    1717  return printf ("Last-Modified: %s\n", buf); 
     18} 
     19 
     20int 
     21header_not_modified (void) 
     22{ 
     23  fprintf (stderr, "304 Not Modified\n"); 
     24  return printf ("Status: 304 Not Modified\n"); 
    1825} 
    1926 
  • fastphoto/trunk/src/header.h

    r140 r148  
    55int header_content_length (int len); 
    66int header_last_modified (time_t mtime); 
     7int header_not_modified (void); 
    78int header_end (void); 
    89 
  • fastphoto/trunk/src/httpdate.c

    r146 r148  
    1111static char * months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 
    1212                          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 
     13 
     14void 
     15httpdate_init (void) 
     16{ 
     17  tzset(); 
     18} 
    1319 
    1420int 
     
    5561  d.tm_year -= 1900; 
    5662 
     63  d.tm_sec -= timezone; 
     64 
    5765  return mktime (&d); 
    5866} 
  • fastphoto/trunk/src/httpdate.h

    r144 r148  
    44#include <time.h> 
    55 
     6void httpdate_init (void); 
    67int httpdate_snprint (char * buf, int n, time_t mtime); 
    78time_t httpdate_parse (char * s, int n); 
  • fastphoto/trunk/src/main.c

    r147 r148  
    148148   
    149149    memset (&params, 0, sizeof (fastphoto_t)); 
     150 
     151    cgi = cgi_init(&params); 
    150152   
    151     if (cgi_init(&params)) { 
    152         cgi = 1; 
     153    if (cgi == 1) { 
    153154        header_content_type_jpeg (); 
     155    } else if (cgi == HTTP_NOT_MODIFIED) { 
     156      header_not_modified(); 
     157      header_end(); 
     158      goto cleanup; 
    154159    } else { 
    155160        err = cmd_init(&params, argc, argv); 
     
    178183    } 
    179184 
     185 cleanup: 
     186 
    180187    if (params.data) free (params.data); 
    181188