mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Make default content-type text/html
This commit is contained in:
		
							parent
							
								
									fdf38b23c8
								
							
						
					
					
						commit
						02af920a0f
					
				
					 3 changed files with 19 additions and 3 deletions
				
			
		|  | @ -1,6 +1,17 @@ | ||||||
| require "./spec_helper" | require "./spec_helper" | ||||||
| 
 | 
 | ||||||
| describe "Context" do | describe "Context" do | ||||||
|  |   it "sets content type" do | ||||||
|  |     kemal = Kemal::Handler.new | ||||||
|  |     kemal.add_route "GET", "/" do |env| | ||||||
|  |       "Hello" | ||||||
|  |     end | ||||||
|  |     request = HTTP::Request.new("GET", "/") | ||||||
|  |     io_with_context = create_request_and_return_io(kemal, request) | ||||||
|  |     client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) | ||||||
|  |     client_response.headers["Content-Type"].should eq("text/html") | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   it "sets content type" do |   it "sets content type" do | ||||||
|     kemal = Kemal::Handler.new |     kemal = Kemal::Handler.new | ||||||
|     kemal.add_route "GET", "/" do |env| |     kemal.add_route "GET", "/" do |env| | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ class Kemal::Handler < HTTP::Handler | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def call(context) |   def call(context) | ||||||
|  |     context.response.content_type = "text/html" | ||||||
|     response = process_request(context) |     response = process_request(context) | ||||||
|     response || call_next(context) |     response || call_next(context) | ||||||
|   end |   end | ||||||
|  | @ -31,6 +32,7 @@ class Kemal::Handler < HTTP::Handler | ||||||
|       route = lookup.payload as Route |       route = lookup.payload as Route | ||||||
|       if route.match?(context.request) |       if route.match?(context.request) | ||||||
|         begin |         begin | ||||||
|  |           context.response.content_type = "text/html" | ||||||
|           body = route.handler.call(context).to_s |           body = route.handler.call(context).to_s | ||||||
|           context.response.print body |           context.response.print body | ||||||
|           return context |           return context | ||||||
|  |  | ||||||
|  | @ -18,7 +18,8 @@ def render_403(context) | ||||||
|       </html> |       </html> | ||||||
|   HTML |   HTML | ||||||
|   context.response.status_code = 403 |   context.response.status_code = 403 | ||||||
|   context.response.puts template |   context.response.print template | ||||||
|  |   context | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| # Template for 404 Not Found | # Template for 404 Not Found | ||||||
|  | @ -40,7 +41,8 @@ def render_404(context) | ||||||
|       </html> |       </html> | ||||||
|   HTML |   HTML | ||||||
|   context.response.status_code = 404 |   context.response.status_code = 404 | ||||||
|   context.response.puts template |   context.response.print template | ||||||
|  |   context | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| # Template for 500 Internal Server Error | # Template for 500 Internal Server Error | ||||||
|  | @ -62,5 +64,6 @@ def render_500(context, ex) | ||||||
|       </html> |       </html> | ||||||
|   HTML |   HTML | ||||||
|   context.response.status_code = 500 |   context.response.status_code = 500 | ||||||
|   context.response.puts template |   context.response.print template | ||||||
|  |   context | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue