-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2, 1.3.1
-
beta
-
generic, x86
-
generic, windows_98
Name: wl91122 Date: 08/18/99
java -version:
java version "1.2.2"
HotSpot VM (1.0.1, mixed mode, build c)
Run the following program (tested on NT, alter the filenames to
match a real file on your local disk, e.g. *.txt):
---------------------%<-----------------
import java.io.File;
import java.net.URL;
public class FileURLConnectionTest extends Object {
public static void main (String args[]) throws Exception {
String test = "d:\\temp\\nrlog.txt";
System.out.println (test + '\t' + new File (test).toURL ().openConnection ().getContentType ());
test = "d:\\temp\\";
System.out.println (test + '\t' + new File (test).toURL ().openConnection ().getContentType ());
test = "d:\\temp";
System.out.println (test + '\t' + new File (test).toURL ().openConnection ().getContentType ());
test = "file://localhost/d:/temp/nrlog.txt";
System.out.println (test + '\t' + new URL (test).openConnection ().getContentType ());
test = "file://localhost/d:/temp/";
System.out.println (test + '\t' + new URL (test).openConnection ().getContentType ());
test = "file://localhost/d:/temp";
System.out.println (test + '\t' + new URL (test).openConnection ().getContentType ());
}
}
-----------------%<---------------
Output I received:
------------------%<-------------
d:\temp\nrlog.txt text/plain
d:\temp\ text/html
d:\temp text/html
file://localhost/d:/temp/nrlog.txt text/plain
file://localhost/d:/temp/ text/html
file://localhost/d:/temp content/unknown
------------------%<-------------
For the case of the directories, an HTML directory listing is
produced by the connection, so the content type should be
text/html.
There appear to be two problems in the class sun.net.www.protocol.file.FileURLConnection:
1. In initializeHeaders(), if isDirectory is true, then the line is run:
properties.add(CONTENT_LENGTH, TEXT_HTML);
which should instead read:
properties.add(CONTENT_TYPE, TEXT_HTML);
This probably accounts for the content/unknown instead of the desired
text/html return for the last item.
2. That there is a discrepancy between the last two items is
strange, I did not see an explanation.
(Review ID: 94034)
======================================================================
- duplicates
-
JDK-4717627 FileURLConnection sets wrong header field for directories
-
- Closed
-
- relates to
-
JDK-4057354 For JDK 2.0: file: and ftp: protocols have hard-wired HotJava dependencies
-
- Resolved
-