--- src/http.c.orig	2004-02-08 23:50:40.000000000 -0600
+++ src/http.c	2004-02-17 13:43:16.665423056 -0600
@@ -1,4 +1,4 @@
-/* HTTP support.
+/* HTTP support
    Copyright (C) 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
@@ -986,6 +986,7 @@
   double dltime;		/* time it took to download the data */
   const char *referer;		/* value of the referer header. */
   char **local_file;		/* local file. */
+  time_t tml;			/* local time-stamp */
 };
 
 static void
@@ -1028,7 +1029,7 @@
 gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
 {
   struct request *req;
-
+	  
   char *type;
   char *user, *passwd;
   char *proxyauth;
@@ -1256,7 +1257,16 @@
 			  aprintf ("%ld", post_data_size), rel_value);
     }
 
-  /* Add the user headers. */
+  if (opt.timestamping && !strcmp (request_method (req), "GET") && hs->tml != -1)
+    { 
+	  char http_time[30];
+	  struct tm * gmt_tm;
+	  gmt_tm = gmtime (&hs->tml);
+	  strftime(http_time,30, "%a, %d %b %Y %H:%M:%S GMT", gmt_tm);
+	  request_set_header (req, "If-Modified-Since", xstrdup (http_time), rel_value);		
+	}
+
+	/* Add the user headers. */
   if (opt.user_headers)
     {
       int i;
@@ -1756,15 +1766,16 @@
 	   int *dt, struct url *proxy)
 {
   int count;
-  int use_ts, got_head = 0;	/* time-stamping info */
+  int use_ts, got_head = 0;		/* time-stamping info */
   char *filename_plus_orig_suffix;
   char *local_filename = NULL;
   char *tms, *locf, *tmrate;
   uerr_t err;
-  time_t tml = -1, tmr = -1;	/* local and remote time-stamps */
+  time_t tmr = -1;	/* remote time-stamp */
   long local_size = 0;		/* the size of the local file */
   size_t filename_len;
   struct http_stat hstat;	/* HTTP status */
+  hstat.tml = -1;       
   struct stat st;
   char *dummy = NULL;
 
@@ -1880,11 +1891,11 @@
 	   skip a download. */
 	{
 	  use_ts = 1;
-	  tml = st.st_mtime;
+	  hstat.tml = st.st_mtime;
 #ifdef WINDOWS
 	  /* Modification time granularity is 2 seconds for Windows, so
 	     increase local time by 1 second for later comparison. */
-	  tml++;
+	  hstat.tml++;
 #endif
 	  local_size = st.st_size;
 	  got_head = 0;
@@ -2030,6 +2041,18 @@
 	}
       if (!(*dt & RETROKF))
 	{
+	  /* If server replies 'Not Modified' we need to return
+		as if the file was recieved successfully */
+	  if (opt.timestamping && hstat.statcode == 304)
+	    {
+		logprintf (LOG_VERBOSE, _("\
+Server file no newer than local file `%s' -- not retrieving.\n\n"),
+			     local_filename);
+		  free_hstat (&hstat);
+		  xfree_null (dummy);
+		  *dt |= RETROKF;
+		  return RETROK;
+	    }
 	  if (!opt.verbose)
 	    {
 	      /* #### Ugly ugly ugly! */
@@ -2045,13 +2068,13 @@
 	  return WRONGCODE;
 	}
 
-      /* Did we get the time-stamp?  */
-      if (!got_head)
+      /* Did we get the time-stamp with the file?  */
+      if (!(*dt & HEAD_ONLY))
 	{
 	  if (opt.timestamping && !hstat.remote_time)
 	    {
 	      logputs (LOG_NOTQUIET, _("\
-Last-modified header missing -- time-stamps turned off.\n"));
+Last-modified header missing -- last modified set to current time. \n"));
 	    }
 	  else if (hstat.remote_time)
 	    {
@@ -2059,41 +2082,23 @@
 	      tmr = http_atotm (hstat.remote_time);
 	      if (tmr == (time_t) (-1))
 		logputs (LOG_VERBOSE, _("\
-Last-modified header invalid -- time-stamp ignored.\n"));
+Last-modified header invalid -- last modified set to current time. \n"));
 	    }
 	}
 
       /* The time-stamping section.  */
       if (use_ts)
 	{
-	  got_head = 1;
+ 	  got_head = 1;
 	  *dt &= ~HEAD_ONLY;
 	  use_ts = 0;		/* no more time-stamping */
 	  count = 0;		/* the retrieve count for HEAD is
 				   reset */
-	  if (hstat.remote_time && tmr != (time_t) (-1))
+	  if (hstat.contlen == -1 || local_size != hstat.contlen)
 	    {
-	      /* Now time-stamping can be used validly.  Time-stamping
-		 means that if the sizes of the local and remote file
-		 match, and local file is newer than the remote file,
-		 it will not be retrieved.  Otherwise, the normal
-		 download procedure is resumed.  */
-	      if (tml >= tmr &&
-		  (hstat.contlen == -1 || local_size == hstat.contlen))
-		{
-		  logprintf (LOG_VERBOSE, _("\
-Server file no newer than local file `%s' -- not retrieving.\n\n"),
-			     local_filename);
-		  free_hstat (&hstat);
-		  xfree_null (dummy);
-		  return RETROK;
-		}
-	      else if (tml >= tmr)
-		logprintf (LOG_VERBOSE, _("\
+			logprintf (LOG_VERBOSE, _("\
 The sizes do not match (local %ld) -- retrieving.\n"), local_size);
-	      else
-		logputs (LOG_VERBOSE,
-			 _("Remote file is newer, retrieving.\n"));
+			hstat.tml = -1;   /*Force gethttp() to retreive file */
 	    }
 	  free_hstat (&hstat);
 	  continue;
