summaryrefslogtreecommitdiff
path: root/apps/JAWS
diff options
context:
space:
mode:
authorjxh <jxh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-06-12 21:25:39 +0000
committerjxh <jxh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-06-12 21:25:39 +0000
commitf94fbdae1362b6f6a79ac55b72a5eaa17b99f977 (patch)
tree56e19c4d01978e9af7958cbdbe6ad8c65a9dce15 /apps/JAWS
parentd393ed4acb66ee1865990684a689cebf03556004 (diff)
downloadATCD-f94fbdae1362b6f6a79ac55b72a5eaa17b99f977.tar.gz
Support content length, and change Date handling for WinNT. THanks
to Greg Gallant (gcg@micrografx.com) for the fixes!
Diffstat (limited to 'apps/JAWS')
-rw-r--r--apps/JAWS/ChangeLog8
-rw-r--r--apps/JAWS/server/HTTP_Helpers.cpp25
-rw-r--r--apps/JAWS/server/HTTP_Response.cpp31
3 files changed, 48 insertions, 16 deletions
diff --git a/apps/JAWS/ChangeLog b/apps/JAWS/ChangeLog
index 83c533aeaee..c94c236ea68 100644
--- a/apps/JAWS/ChangeLog
+++ b/apps/JAWS/ChangeLog
@@ -1,3 +1,11 @@
+Mon Jun 12 14:22:35 PDT 2000 James Hu <jxh@entera.com>
+
+ * server/HTTP_Response.cpp: Added content length support.
+ Thanks to Greg Gallant (gcg@micrografx.com) for the fixes!
+
+ * server/HTTP_Helpers.cpp: Fix date handling for NT.
+ Thanks to Greg Gallant (gcg@micrografx.com) for the fixes!
+
Sun Jun 4 14:57:04 2000 Darrell Brunsch <brunsch@uci.edu>
* clients/WebSTONE/bin/WebStone-common.pl:
diff --git a/apps/JAWS/server/HTTP_Helpers.cpp b/apps/JAWS/server/HTTP_Helpers.cpp
index 100ee7e1ccb..b2a9e0aa891 100644
--- a/apps/JAWS/server/HTTP_Helpers.cpp
+++ b/apps/JAWS/server/HTTP_Helpers.cpp
@@ -113,19 +113,12 @@ HTTP_Helper::HTTP_date (void)
{
ACE_MT (ACE_Guard<ACE_SYNCH_MUTEX> m (HTTP_Helper::mutex_));
- time_t tloc;
- struct tm tms;
-
if (HTTP_Helper::date_string_ == 0)
{
// 40 bytes is all I need.
- HTTP_Helper::date_string_ = new char[40];
+ ACE_NEW_RETURN (HTTP_Helper::date_string_, char[40], 0);
- if (ACE_OS::time (&tloc) != (time_t) -1
- && ACE_OS::gmtime_r (&tloc, &tms) != NULL)
- ACE_OS::strftime (HTTP_Helper::date_string_, 40,
- "%a, %d %b %Y %T GMT", &tms);
- else
+ if (!HTTP_Helper::HTTP_date (HTTP_Helper::date_string_))
{
delete [] HTTP_Helper::date_string_;
HTTP_Helper::date_string_ = 0;
@@ -139,13 +132,25 @@ HTTP_Helper::HTTP_date (void)
const char *
HTTP_Helper::HTTP_date (char *s)
{
+ // Return the date-string formatted per HTTP standards. Time must
+ // be in UTC, so using the 'strftime' call (which obeys the locale)
+ // isn't correct.
+ static const char* months[] = {"Jan","Feb","Mar","Apr","May","Jun",
+ "Jul","Aug","Sep","Oct","Nov","Dec"};
+ static const char* days[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
+
time_t tloc;
struct tm tms;
char * date_string = s;
if (ACE_OS::time (&tloc) != (time_t) -1
&& ACE_OS::gmtime_r (&tloc, &tms) != NULL)
- ACE_OS::strftime (date_string, 40, "%a, %d %b %Y %T GMT", &tms);
+ {
+ ACE_OS::sprintf (date_string,
+ "%s, %02.2d %s %4.4d %02.2d:%02.2d:%02.2d GMT",
+ days[tms.tm_wday], tms.tm_mday, months[tms.tm_mon],
+ tms.tm_year + 1900, tms.tm_hour, tms.tm_min, tms.tm_sec);
+ }
else
date_string = 0;
diff --git a/apps/JAWS/server/HTTP_Response.cpp b/apps/JAWS/server/HTTP_Response.cpp
index 953a5bc5cba..2ffebf27154 100644
--- a/apps/JAWS/server/HTTP_Response.cpp
+++ b/apps/JAWS/server/HTTP_Response.cpp
@@ -341,15 +341,34 @@ HTTP_Response::build_headers (void)
// 40 bytes is the maximum length needed to store the date
if (HTTP_Helper::HTTP_date (date_ptr) != 0)
- HTTP_HEADER_LENGTH +=
- ACE_OS::sprintf (HTTP_HEADER+HTTP_HEADER_LENGTH,
+ HTTP_HEADER_LENGTH +=
+ ACE_OS::sprintf (HTTP_HEADER+HTTP_HEADER_LENGTH,
"Date: %s\r\n", date_ptr);
- if (! this->request_.cgi ())
- HTTP_HEADER_LENGTH +=
- ACE_OS::sprintf (HTTP_HEADER+HTTP_HEADER_LENGTH,
- "Content-type: %s\r\n\r\n",
+ if (! this->request_.cgi ()) {
+ HTTP_HEADER_LENGTH +=
+ ACE_OS::sprintf (HTTP_HEADER+HTTP_HEADER_LENGTH,
+ "Content-type: %s\r\n",
"text/html");
+
+ struct stat file_stat;
+ // If possible, add the Content-length field to the header.
+ // @@ Note that using 'ACE_OS::stat' is a hack. Normally,
+ // a web browser will have a 'virtual' file system. In a
+ // VFS, 'stat' might not reference the correct location.
+ if ((this->request_.type () == HTTP_Request::GET) &&
+ (ACE_OS::stat (this->request_.path (), &file_stat) == 0))
+ {
+ HTTP_HEADER_LENGTH +=
+ ACE_OS::sprintf (HTTP_HEADER+HTTP_HEADER_LENGTH,
+ "Content-length: %u\r\n", file_stat.st_size);
+ }
+
+ // Complete header with empty line and adjust header length.
+ HTTP_HEADER[HTTP_HEADER_LENGTH++] = '\r';
+ HTTP_HEADER[HTTP_HEADER_LENGTH++] = '\n';
+ }
+
#else
if (! this->request_.cgi ())
HTTP_HEADER = "HTTP/1.0 200 OK\r\n"