Name: paC48320 Date: 11/13/97
The JDK http handler implementation class:
sun.net.www.protocol.HttpURLConnection
ignores any "IfModifiedSince" value that was set by calling
java.net.URLConnection.setIfModifiedSince(long)
In other words, it fails to write the HTTP Header entry that,
according to RFC1945, should look like:
If-Modified-Since = "If-Modified-Since" ":" HTTP-date
Run the module supplied below, as follows:
% java HTTPTest http://<someValidURL>
And you should see a response code of 304 since I set the
if-modified-since date to be way in the future.
Instead, you'll see a response code of 200.
NOTE: If you look inside of sun.net.www.protocol.http.HttpURLConnection
you will see that there is no code to handle
the setting of the If-Modified-Since header entry.
The code in writeRequests should look something like:
if ( getModifiedSince() != 0 )
{
requests.setIfNotSet("If-Modified-Since", getModifiedSince());
}
Except that you will have to use DateFormat to convert the getModifiedSince()
date into the HTTP-Date String format required by HTTP.
//
// Test module for broken If-Modified-Since HTTP Header...
//
// ###@###.###
//
import java.net.*;
public class HTTPTest extends Object
{
public HTTPTest()
{
}
public static final void main(String argv[])
{
try
{
URL testURL = new URL(argv[0]);
URLConnection URLConn = testURL.openConnection();
HttpURLConnection httpConn;
if ( URLConn instanceof HttpURLConnection )
{
httpConn = (HttpURLConnection)URLConn;
httpConn.setAllowUserInteraction(false);
httpConn.setIfModifiedSince(999000000000l);
httpConn.connect();
System.out.println("URL:" + httpConn.getURL()
+ "\nContent-encoding:"
+ httpConn.getContentEncoding()
+ "\nContent-length:"
+ httpConn.getContentLength()
+ "\nContent-type:"
+ httpConn.getContentType()
+ "\nDate:"
+ httpConn.getDate()
+ "\nIf-Modified-Since:"
+ httpConn.getIfModifiedSince()
+ "\nLast-Modified:"
+ httpConn.getLastModified());
System.out.println(httpConn.getRequestMethod()
+ " " + httpConn.getResponseCode()
+ " " + httpConn.getResponseMessage());
for ( int i = 0; ;i++ )
{
httpConn.getHeaderField(i);
if ( httpConn.getHeaderFieldKey(i) == null )
{
break;
}
System.out.println(httpConn.getHeaderFieldKey(i)
+ ":"
+ httpConn.getHeaderField(i));
}
}
else
{
System.out.println("URL is not a cache candidate.");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
(Review ID: 19884)
======================================================================
- relates to
-
JDK-4357206 TEST_BUG: regression test Modified.java makes incorrect assumptions
-
- Resolved
-