Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4717627

FileURLConnection sets wrong header field for directories

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.1
    • core-libs
    • x86
    • windows_98



      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)
      ======================================================================

            jccollet Jean-Christophe Collet (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: