Skip to content

Falcon App Server: Request Body Cannot Be Rewound for Multiple Reads #27

@franciscojmc

Description

@franciscojmc

Description

When using the Falcon app server (which uses protocol-rack internally), request bodies cannot be properly rewound for subsequent reads. After the first read, subsequent reads return an empty string even after calling rewind.

Steps to Reproduce

  1. Create a simple Rack application that reads a request body twice
  2. Run it with Falcon server
  3. POST data to the endpoint
  4. Observe that the second read returns an empty string

Test

# typed: true
# frozen_string_literal: true

require "rack"

class BodyTestApp
  def call(env)
    # Get the request body
    body = env["rack.input"]

    # First read
    body.rewind
    first_read = body.read

    # Second read
    body.rewind
    second_read = body.read

    # Response showing both reads
    response_body = "First read: #{first_read.inspect}\n\nSecond read: #{second_read.inspect}"

    [200, { "Content-Type" => "text/plain" }, [response_body]]
  end
end

Output

➜ curl -X POST -d "This is test data" http://localhost:9292
First read: "This is test data"

Second read: ""

Expected Behavior

Both reads should return the same data after calling rewind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions