[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[PATCH] Add getHeader() and getDateHeader() testing functionality to
From: Sergey Jukov <sergey@total-knowledge.com>
diff --git a/ChangeLog b/ChangeLog
index 83a0a1d..9ab8443 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
-Sergey Jukov <sergey@total-knowledge> Fri, 9 Sep 2006 10:30:00 -0800
-- Add extra path test functionality to headers.cpp.
+Sergey Jukov <sergey@total-knowledge> Tue, 13 Sep 2006 10:30:00 -0800
+- Add getHeader() and getDateHeader() test functionality to
+headers.cpp. Add testHeader perl script.
Sergey Jukov <sergey@total-knowledge.com> Mon, 4 Sep 2006 22:10:03 -0800
- Add Utils servlet test scripts
diff --git a/engine.xml b/engine.xml
index 0851951..4dec2a8 100644
--- a/engine.xml
+++ b/engine.xml
@@ -5,8 +5,6 @@
<app name="test">
<servlet name="IndexServlet" dso="./debug/index/IndexServlet.so"/>
<servlet name="HelloServlet" dso="./debug/hello/HelloServlet.so"/>
-<!-- <servlet name="FirstTestServlet"
-dso="./debug/firsttest/FirstTestServlet.so"/> -->
<servlet name="FileUploadServlet" dso="./debug/fileupload/FileUploadServlet.so"/>
<servlet name="RedirectServlet" dso="./debug/redirect/RedirectServlet.so"/>
<servlet name="CookiesServlet" dso="./debug/cookies/CookiesServlet.so"/>
diff --git a/headers/headers.cpp b/headers/headers.cpp
index 1b6897b..530755d 100644
--- a/headers/headers.cpp
+++ b/headers/headers.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2004 by Ilya A. Volynets-Evenbakh *
+ * Copyright (C) 2006 by Ilya A. Volynets-Evenbakh *
* ilya@total-knowledge.com *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -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,20 +38,15 @@ void HeadersServlet::service(servlet::Ht
out<<*it<<':'<<*vit<<std::endl;
}
out<<"============\nProtocol="<<req.getProtocol()<<std::endl;
-
-
-
out << "\n==========\nHTTP Method = "+req.getMethod();
-
- //std:: string methodName = "X-Test-Header";
- //out << "\nInteger Header = "+req.getIntHeader(methodName);
- out << "\nPath = "+req.getPathInfo();
-
-
- //out << "\nPath Translated = "+req.getPathTranslated();
-
+ 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 2814471..6b3820e 100644
--- a/headers/headers.h
+++ b/headers/headers.h
@@ -30,12 +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
-Also it displays HTTP method and extra path information. To test it,
-provide additional information between servlet path and a query string.
-For example, in URL
-http://www.total-knowledge.com/csp/HeadersServlet/add/path?key=value
-extra path information is "/add/path". Returns null if there was no
-extra path information provided.
+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