Re: ServletUnitHttpRequest.getDateHeader() always "returns -1"?

"Wolfgang Fahl - BITPlan" <[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Organization bitplan GmbH
Message-ID <[email protected]>
Yu Chen wrote:

> I noticed that ServletUnitHttpRequest.getDateHeader() always "returns

> -1" (different than getHeader() ). Am I wrong or it must be a good

> reason why it is hard-coded that way?!

Thanks for the input. I've added the following test to correct the
functionality:

/**

*

test

getting

a

date

header;

*

@throws

Exception

*/

public

void

testDateHeaderAccess()

throws

Exception {

WebRequest wr =

new

GetMethodWebRequest(

"http://localhost/simple"

);

String dateStr=

"Mon, 26 Jul 1997 05:00:00 GMT"

;

Date testDate=

new

Date(dateStr);

wr.setHeaderField(

"Expires"

, dateStr );

HttpServletRequest request =

new

ServletUnitHttpRequest(

NULL_SERVLET_REQUEST

, wr,

_context

,

new

Hashtable(),

NO_MESSAGE_BODY

);

String
dateStrRequest=request.getHeader(

"Expires"

);

assertTrue(

"Expires header
field"

,dateStrRequest.equals(dateStr));

// invalid date headers return -1

long

requestDate=request.getDateHeader(

"invalid"

);

assertTrue(

"invalid date header
field"

,requestDate==-1);

// valid date header field return the millisecs

requestDate=request.

getDateHeader

(

"Expires"

);

assertTrue(

"Expires date header
field"

,requestDate==testDate.getTime());

}

and changed the code.

public

long

getDateHeader

( String name ) {

try

{

String

dateString

=getHeader(name);

Date headerDate=

new

Date(

dateString

);

return

headerDate.getTime();

}

catch

(Exception e) {

return

-1;

}

}

The result is in the subversion repository on Sourceforge.net

Yours

Wolfgang

BITPlan - smart solutions

Pater-Delp-Str. 1, D-47877 Willich Schiefbahn

Tel. +49 1805 - BITPLAN / +49 1805 248 752, Fax +49 2154 811-481

Web: http://www.bitplan.de

bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548, Geschäftsführer: Wolfgang Fahl

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.