Repository: puma/puma
File: lib/puma/request.rb (Ruby)

Code before:
      end

      cork_socket socket

      if resp_info[:no_body]
        if content_length and status != 204
          io_buffer.append CONTENT_LENGTH_S, content_length.to_s, line_ending
        end

        io_buffer << LINE_END
        fast_write_str socket, io_buffer.rd_and_rst
        socket.flush
        return keep_alive
      end
      if content_length
        io_buffer.append CONTENT_LENGTH_S, content_length.to_s, line_ending
        chunked = false
      elsif !response_hijack and resp_info[:allow_chunked]
        io_buffer << TRANSFER_ENCODING_CHUNKED
        chunked = true
      end

      io_buffer << line_ending

      if response_hijack
        fast_write_str socket, io_buffer.rd_and_rst
        response_hijack.call socket
        return :async
      end

      fast_write_response socket, body, io_buffer, chunked, content_length.to_i
      body.close if close_body
      keep_alive
    end

    # @param env [Hash] see Puma::Client#env, from request
    # @return [Puma::Const::PORT_443,Puma::Const::PORT_80]
    #
    def default_server_port(env)
      if ['on', HTTPS].include?(env[HTTPS_KEY]) || env[HTTP_X_FORWARDED_PROTO].to_s[0...5] == HTTPS || env[HTTP_X_FORWARDED_SCHEME] == HTTPS || env[HTTP_X_FORWARDED_SSL] == "on"
        PORT_443
      else
        PORT_80
      end
    end

    # Used to write 'early hints', 'no body' responses, 'hijacked' responses,
    # and body segments (called by `fast_write_response`).
    # Writes a string to a socket (normally `Client#io`) using `write_nonblock`.
    # Large strings may not be written in one pass, especially if `io` is a
    # `MiniSSL::Socket`.

Review comment (suggestion):
```suggestion
        fast_write_str socket, io_buffer.read_and_reset
```

Code after:
      end

      cork_socket socket

      if resp_info[:no_body]
        if content_length and status != 204
          io_buffer.append CONTENT_LENGTH_S, content_length.to_s, line_ending
        end

        io_buffer << LINE_END
        fast_write_str socket, io_buffer.read_and_reset
        socket.flush
        return keep_alive
      end
      if content_length
        io_buffer.append CONTENT_LENGTH_S, content_length.to_s, line_ending
        chunked = false
      elsif !response_hijack and resp_info[:allow_chunked]
        io_buffer << TRANSFER_ENCODING_CHUNKED
        chunked = true
      end

      io_buffer << line_ending

      if response_hijack
        fast_write_str socket, io_buffer.read_and_reset
        response_hijack.call socket
        return :async
      end

      fast_write_response socket, body, io_buffer, chunked, content_length.to_i
      body.close if close_body
      keep_alive
    end

    # @param env [Hash] see Puma::Client#env, from request
    # @return [Puma::Const::PORT_443,Puma::Const::PORT_80]
    #
    def default_server_port(env)
      if ['on', HTTPS].include?(env[HTTPS_KEY]) || env[HTTP_X_FORWARDED_PROTO].to_s[0...5] == HTTPS || env[HTTP_X_FORWARDED_SCHEME] == HTTPS || env[HTTP_X_FORWARDED_SSL] == "on"
        PORT_443
      else
        PORT_80
      end
    end

    # Used to write 'early hints', 'no body' responses, 'hijacked' responses,
    # and body segments (called by `fast_write_response`).
    # Writes a string to a socket (normally `Client#io`) using `write_nonblock`.
    # Large strings may not be written in one pass, especially if `io` is a
    # `MiniSSL::Socket`.