CPPSERV


Home Projects Jobs Clientele Contact

cppserv


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add test functionality for getHeader() and getDateHeader() in



From: Sergey Jukov <sergey@total-knowledge.com>

diff --git a/ChangeLog b/ChangeLog
index 0dac80a..a6d9bd1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sergey Jukov <sergey@total-knowledge.com>            Wed, 13 Sep 2006 16:20:00 -0800
+- Add testing getHeader() and getDateHeader() functionality for
+headers.cpp and headers.h. Add testHeaders.pl for testing date header parser.
+
 Ilya A. Volynets-Evenbakh <ilya@total-knowledge.com> Fri, 13 Sep 2006 14:22:11 -0800
 - Fix few copyright headers
 
diff --git a/headers/headers.cpp b/headers/headers.cpp
index 4a253c8..cf247e2 100644
--- a/headers/headers.cpp
+++ b/headers/headers.cpp
@@ -18,6 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 #include "headers.h"
+#include <iostream>
+#include <sstream>
 
 void HeadersServlet::service(servlet::HttpServletRequest& req, servlet::HttpServletResponse& resp)
 {
@@ -36,6 +38,14 @@ void HeadersServlet::service(servlet::Ht
 		    out<<*it<<':'<<*vit<<std::endl;
 	}
 	out<<"============\nProtocol="<<req.getProtocol()<<std::endl;
+	out << "\n==========\nHTTP Method = "+req.getMethod();
+	std:: string testHeaderName = "if-modified-since";
+	out << "\n" << testHeaderName+":"+req.getHeader(testHeaderName); 
+	long l = req.getDateHeader(testHeaderName);
+        std:: stringstream s;
+        s << l;
+	std:: string dateHeader = s.str();
+	out << "\n" << testHeaderName+" value = "+dateHeader; 
 	out<<"</PRE>";
 	renderFooter(out);
 }
diff --git a/headers/headers.h b/headers/headers.h
index 8bf8b31..3247dbf 100644
--- a/headers/headers.h
+++ b/headers/headers.h
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2004-2005 by Ilya A. Volynets-Evenbakh                  *
+ *   Copyright (C) 2004-2006 by Ilya A. Volynets-Evenbakh                  *
  *   ilya@total-knowledge.com                                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -30,6 +30,13 @@ This servlet demonstrates how to set res
 at request headers.
 It displays a page, with values of all request headers,
 and sends X-Test-Header: header. It also sets Pragma: no-cache
+It displays HTTP method with which this request was made, work of getHeader()
+which returns the value of specified request header(null if there was no such 
+header in HTTP request) and getDateHeader() which returns the number of 
+milliseconds since January 1, 1970 GMT, or -1 if the named header was not 
+included with the request. Throws IllegalArgumentException if the header value
+can't be converted to a date.
+Example provided for If-Modified-Since HTTP request header using testHeaders.pl
 
 @author Ilya A. Volynets-Evenbakh
 */
diff --git a/headers/testHeaders.pl b/headers/testHeaders.pl
new file mode 100644
index 0000000..c5cf559
--- /dev/null
+++ b/headers/testHeaders.pl
@@ -0,0 +1,40 @@
+use LWP::UserAgent;
+$ua = LWP::UserAgent->new;
+
+my $req = HTTP::Request->new(POST => 'http://localhost/~sergey/csp/HeadersServlet');
+$req->content_type('application/x-www-form-urlencoded');
+$req->content('key=value');
+
+my $headerName = "If-Modified-Since";
+
+my @headerValues = (
+'Tue, 9 Sep 2006 12:45:26 GMT',
+'Mon, 33 Sep 06 12:00:00 GMT',
+''
+);
+
+
+
+foreach $headerValue (@headerValues)
+{
+
+    $req->header($headerName => $headerValue);
+
+    my $res = $ua->request($req);
+
+    if ($res->is_success) {
+
+	print $res->content."\n\n------------------------------------------------------\n\n\n";
+
+    }
+    else {
+	print $res->status_line, "\n";
+    }
+
+}
+
+
+
+
+
+
-- 
1.4.2


Authoright © Total Knowledge: 2001-2008