title: Why is the HTTP header 'content-length' not always set?
body: <p>I am requesting files from an IBM HTTP server via a Websphere App Server (7FP19). For most files I get the content-length header but for some, not. I discovered that when I set the last-modified value in the request to '0' then I get the content-length for all files.</p>
  
  <p>This seems a bit wierd to me. Does anyone know why this might be or is it just a coincidence?</p>
  
  <p>Here is some code:</p>
  
  <pre><code>    connection = (HttpURLConnection) url.openConnection();
      for (String value : cookies.values()) {
          connection.addRequestProperty("Cookie", value); //$NON-NLS-1$
      }
      connection.setDoOutput(true);
      connection.setRequestProperty("User-Agent", USER_AGENT); //$NON-NLS-1$
      //connection.setIfModifiedSince(localLastModified);
      connection.setIfModifiedSince(0);
  
      OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
      wr.write(post);
      wr.flush();
      wr.close();
  ....
      // set file attributes
      long remoteDate = connection.getLastModified();
      if(rc == 304)
          data.lastModified = localLastModified;
      else
          data.lastModified = remoteDate;
      data.retCode = connection.getResponseCode();
      data.contentType = connection.getContentType();
      data.contentEncoding = connection.getContentEncoding();
  
      int expectedLength = connection.getContentLength();
      if(expectedLength &lt; 0) {
          log.warn("Expected length: " + expectedLength);
      }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>this was running on Wesphere FP19. I returned to FP15 and the problem was gone. The length is always returned. </p>