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

Add default_content_type setting. Fixes #1238 #1239

Merged
merged 1 commit into from Mar 19, 2020

Commits on Mar 19, 2020

  1. Add default_content_type setting

    Historically, Sinatra::Response defaults to a text/html Content-Type.
    However, in practice, Sinatra immediately clears this attribute after
    instantiating a new Sinatra::Response object, so this default is some-
    what suspect. Let's break this behavior and have Sinatra::Response
    be Content-Type-less by default, and update the tests to reflect this.
    
    Next, let's introduce a new default_content_type setting that will be
    applied (instead of text/html) if the Content-Type is not set before the
    response is finalized. This will be great for e.g. JSON API developers.
    Let's also make it nil-able to indicate that a default Content-Type
    should never be applied.
    
    Wherever Sinatra is emitting HTML, e.g. in error pages, force the
    Content-Type to text/html.
    
    Finally, clean up the error-handling logic to behave as follows:
    
    * Set the X-Cascade header as early as possible.
    * If an error block matches and returns a value, stop processing and
      return that value.
    * If we have a not found or bad request error, inspect the exception (if
      any) for an error message and present it as the response body if it
      exists, or present a default error message.
    
    The remaining logic is the same otherwise. This should make error
    handlers simpler to write and behave more consistently by not polluting
    the body with a default message when none may be necessary.
    mwpastore authored and jkowens committed Mar 19, 2020
    Copy the full SHA
    996c341 View commit details
    Browse the repository at this point in the history