mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Add log macro
This commit is contained in:
		
							parent
							
								
									265bfb1db2
								
							
						
					
					
						commit
						aabfe4ff99
					
				
					 3 changed files with 14 additions and 4 deletions
				
			
		|  | @ -18,6 +18,7 @@ describe "Logger" do | |||
|     logger = Kemal::Logger.new | ||||
|     logger.handler.should be_a File | ||||
|   end | ||||
| 
 | ||||
|   it "writes to a file in production" do | ||||
|     config = Kemal.config | ||||
|     config.env = "production" | ||||
|  |  | |||
|  | @ -34,3 +34,10 @@ end | |||
| macro public_folder(path) | ||||
|   Kemal.config.public_folder = {{path}} | ||||
| end | ||||
| 
 | ||||
| # Logs to output stream. | ||||
| # development: STDOUT in | ||||
| # production: kemal.log | ||||
| macro log(message) | ||||
|   Kemal::Logger::INSTANCE.write "#{{{message}}}\n" | ||||
| end | ||||
|  |  | |||
|  | @ -10,6 +10,8 @@ module Kemal::Middleware | |||
|   class HTTPBasicAuth < HTTP::Handler | ||||
|     BASIC                 = "Basic" | ||||
|     AUTH                  = "Authorization" | ||||
|     AUTH_MESSAGE          = "Could not verify your access level for that URL.\nYou have to login with proper credentials" | ||||
|     HEADER_LOGIN_REQUIRED = "Basic realm=\"Login Required\"" | ||||
| 
 | ||||
|     def initialize(@username, @password) | ||||
|     end | ||||
|  | @ -23,8 +25,8 @@ module Kemal::Middleware | |||
|         end | ||||
|       end | ||||
|       headers = HTTP::Headers.new | ||||
|       headers["WWW-Authenticate"] = "Basic realm=\"Login Required\"" | ||||
|       HTTP::Response.new(401, "Could not verify your access level for that URL.\nYou have to login with proper credentials", headers, nil, "HTTP/1.1", nil) | ||||
|       headers["WWW-Authenticate"] = HEADER_LOGIN_REQUIRED | ||||
|       HTTP::Response.new(401, AUTH_MESSAGE, headers, nil, "HTTP/1.1", nil) | ||||
|     end | ||||
| 
 | ||||
|     def authorized?(value) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue