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

FileServerHandler::discardRequestBody could be improved

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • None
    • core-libs
    • None
    • b25

      FileServerHandler::discardRequestBody calls InputStream::readAllBytes to read and discard all the request body bytes off the network.

      Since we're going to discard the bytes then we don't really need to accumulate them so using readAllBytes for that seems wasteful.

      The InputStream this is called on is one of the specific InputStream sub classes provided by the server implementation, which deal with clear text vs TLS, chunked vs fixed length etc... At some point they eventually delegate to the socket input stream.

      Possibly InputStream::skip(Integer.MAX_VALUE) could be used instead, after double checking that it's been correctly overridden by the subclasses if needed, or maybe a loop that repeatedly read 1024 bytes until EOF is reached.

      https://github.com/openjdk/jdk/blob/377138c7b58d0dd6f11ef4c4fa5598fd836f39df/src/jdk.httpserver/share/classes/sun/net/httpserver/simpleserver/FileServerHandler.java#L160-L164

            dclarke Darragh Clarke
            dfuchs Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: