Class Http1ResponseWriter

java.lang.Object
dev.relism.flash.http1.Http1ResponseWriter

public final class Http1ResponseWriter extends Object
Serializes a Response as an HTTP/1.1 message. Sole responsibility: response serialization — routing, handler dispatch, and the request loop live in Http1Connection. The status line, Content-Type, Date, every custom header, and Content-Length/Connection are all serialized into ConnectionScratch.responseHead (a reused ByteWriter) before a single OutputStream.write call — not one small write per field, and no BufferedOutputStream coalescing them at the stream layer (this class removes the need for one entirely on the h1 response path). A body at or below Http1Limits.INLINE_BODY_THRESHOLD is copied into the same scratch buffer and goes out in that same syscall; a larger body is written separately right after, since copying it into the head buffer first would cost an extra full-body memcpy the syscall it saves does not pay for. Streaming/chunked bodies write the head, then relay their own bytes as they arrive — by definition unknown or too large to fold into one buffer up front.
  • Method Details

    • writeResponse

      public static void writeResponse(OutputStream out, Response response, HttpMethod method, boolean keepAlive, boolean sendDate, ConnectionScratch scratch) throws IOException
      Writes response to out as a complete HTTP/1.1 message.
      Parameters:
      method - the request method — null is treated as "not HEAD" (used for parser-rejection responses, which never reach a handler and so have no associated method)
      sendDate - whether to include the Date header (FlashConfiguration#isSendDate())
      Throws:
      IOException