Name: nt126004 Date: 07/19/2002
FULL PRODUCT VERSION :
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows 98 SE
A DESCRIPTION OF THE PROBLEM :
When you open a URL connection to a directory using 'file:'
protocol, you get the wrong content-length header. The
problem is in
sun.net.www.protocol.file.FileURLConnection.java.
Line 96 reads (method initializeHeaders()):
properties.add(CONTENT_LENGTH, TEXT_HTML);
instead it must be
properties.add(CONTENT_TYPE, TEXT_HTML);
Moreover, if you call getContentType() on the
FileURLConnection before doing getInputStream() it will not
initialize the headers and will return the wrong value.
EXPECTED VERSUS ACTUAL BEHAVIOR :
getHeaderField("content-length") should return the length
of the stream or -1 but not the conten type ;)
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
URL u = new URL("file:/c:/");
URLConnection uc = u.openConnection();
System.out.println("type1 "+uc.getContentType());
System.out.println("len "+uc.getContentLength());
System.out.println("len2 "+uc.getHeaderField("content-length"));
---------- END SOURCE ----------
(Review ID: 159597)
======================================================================
- duplicates
-
JDK-4263459 Content type of file: URL connection for directories inconsistent.
-
- Resolved
-