rack/rack-test

How to create a POST/PUT/PATCH request without a content type?

sriedel opened this issue · 5 comments

To aid in debugging with curl, I want to block incoming http requests which are expected to have bodies, but do not provide a content type or the wrong content type, and provide a helpful message, instead of having the person come to me claiming "everything is broken".

While testing the implementation, I seem to be able to test requests with "Content-Type : " (i.e. empty value). However I don't see how I can generate a request where the Content-Type header is not set at all, since it's defaulted to 'application/x-www-form-urlencoded' without an obvious way to circumvent this setting.

How can I test requests without a content type set?

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I ran into this as well. This line appears to set the default Content-Type:

env['CONTENT_TYPE'] ||= 'application/x-www-form-urlencoded'

I tried passing in a blank Content-Type. This works, but Rails will throw up an exception if the content_mime_type is ever accessed since a blank string isn't a valid MIME type.

I think you can currently handle this by specifying :input. However, in that case you have to provide your own body, rack-test won't generate a body for you. Will that work for your purposes?

If it would work with rack-test directly, but doesn't work with Rails, sounds like a Rails problem that should be discussed with the Rails developers