Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.8 Multipart PATCH requests fail in minitest(Rack::Multipart::EmptyContentError) #2139

Open
kochetkovandrew opened this issue Dec 6, 2023 · 1 comment

Comments

@kochetkovandrew
Copy link

kochetkovandrew commented Dec 6, 2023

POST requests work:

      post :create, params: {
        attachment: {
          attachment: fixture_file_upload('fixture_file.json', 'text/plain')
        }
      }

But the following PATCH request raises an exception
Minitest::UnexpectedError: ActionController::BadRequest: Invalid request parameters: Rack::Multipart::EmptyContentError

    patch :update, params: {
      id: attachment_id,
      attachment: {
        attachment: fixture_file_upload('fixture_file.json', 'text/plain')
      }
    }

At the same time it works from browser:

@headers="Content-Disposition: form-data; name=\"attachment[attachment]\"; filename=\"fixture_file.json\"\r\nContent-Type: text/plain\r\n">}

But doesn't work from minitest:
@headers="content-disposition: form-data; name=\"attachment[attachment]\"; filename=\"fixture_file.json\"\r\ncontent-type: text/plain\r\ncontent-length: 203\r\n">}

The only differences I can find were capitalized Content-* header names and presence of content-length in minitest request headers (content-length 203 corresponds to the real size of the file). Changing of text/plain to application/json or application/octet-stream had no effect.

Downgrading to rack 2.2.8 solves the issue.
Rails 7.1.2, minitest 5.20.0

@jeremyevans
Copy link
Contributor

Where do the post and patch methods come from? They aren't in minitest or rack. Maybe in rack-test? Are you using an old version of rack-test (before rack-test 2.0.0)?

Can you post a minimal self contained example showing the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants