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

response.headers['Content-Type'] ="text/html;" return Content-Type: text/plain #4

Closed
tablecell opened this issue Sep 24, 2021 · 4 comments

Comments

@tablecell
Copy link

require 'watts'

class Simple < Watts::App
	class EZResource < Watts::Resource
	
		get { 
		response.headers['Content-Type'] ="text/html;charset=utf-8"

		#"Hello, World!\n" 
		ERB.new(File.read("view/test.erb")).result
		
		}
	end

	resource('/', EZResource)
end

curl http://localhost:9292/
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 14

@mustmodify
Copy link

mustmodify commented Jan 30, 2023

@pete I'm also having this issue... any thoughts? I'm guessing, based on a pattern of code like this that I would have to patch Watts to send the right header.

@mustmodify
Copy link

This works, but it's a suboptimal interface IMO

  class BookDropResource < Watts::Resource
    get {
      [
        200,
        {'Content-Type' => 'text/html'},
        [ERB.new(File.read("#{__dir__}/views/book_drop_index.html.erb")).result]
      ]
    }
  end

@mustmodify
Copy link

mustmodify commented Feb 5, 2023

Solution can be found in PR 5

@pete
Copy link
Owner

pete commented Jul 7, 2024

@mustmodify I made a note in PR #5, but so it's here as well, I think it'd be reasonable to do something like an instance method that provides a default Content-Type. The only reservations I'd have about that are that if you try to handle Accept properly, it is more likely to get in the way than help. I'm not enamored of Rack's [code,{headers},[body]] format, but it seems reasonable to stick close to Rack unless there's a reason.

@pete pete closed this as completed Jul 7, 2024
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

3 participants