Crystal 0.25.0 (#452)

This commit is contained in:
Serdar Dogruyol 2018-06-16 18:03:00 +03:00 committed by GitHub
parent c2236acf3a
commit a5870e7d24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 22 deletions

View file

@ -174,7 +174,7 @@ describe "ParamParser" do
body_params.to_s.should eq("")
json_params = Kemal::ParamParser.new(request).json
json_params.should eq({} of String => Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type))
json_params.should eq({} of String => Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any))
end
end

View file

@ -85,7 +85,6 @@ describe "Kemal::RouteHandler" do
post "/" do |env|
skills = env.params.json["skills"].as(Array)
skills_from_languages = skills.map do |skill|
skill = skill.as(Hash)
skill["language"]
end
"Skills #{skills_from_languages.each.join(',')}"

View file

@ -131,7 +131,7 @@ describe Kemal::StaticFileHandler do
end
it "should handle setting custom headers" do
headers = Proc(HTTP::Server::Response, String, File::Stat, Void).new do |response, path, stat|
headers = Proc(HTTP::Server::Response, String, File::Info, Void).new do |response, path, stat|
if path =~ /\.html$/
response.headers.add("Access-Control-Allow-Origin", "*")
end
@ -143,7 +143,7 @@ describe Kemal::StaticFileHandler do
response = handle HTTP::Request.new("GET", "/dir/test.txt")
response.headers.has_key?("Access-Control-Allow-Origin").should be_false
response.headers["Content-Size"].should eq(
File.stat("#{__DIR__}/static/dir/test.txt").size.to_s
File.info("#{__DIR__}/static/dir/test.txt").size.to_s
)
response = handle HTTP::Request.new("GET", "/dir/index.html")

View file

@ -25,27 +25,29 @@ describe "Kemal::WebSocketHandler" do
ws "/" { |socket| socket.send("Match") }
ws "/no_match" { |socket| socket.send "No Match" }
headers = HTTP::Headers{
"Upgrade" => "websocket",
"Connection" => "Upgrade",
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
"Upgrade" => "websocket",
"Connection" => "Upgrade",
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version" => "13",
}
request = HTTP::Request.new("GET", "/", headers)
io_with_context = create_ws_request_and_return_io(handler, request)
io_with_context.to_s.should eq("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-Websocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n\x81\u0005Match")
io_with_context.to_s.should eq("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n\x81\u0005Match")
end
it "fetches named url parameters" do
handler = Kemal::WebSocketHandler::INSTANCE
ws "/:id" { |_, c| c.params.url["id"] }
headers = HTTP::Headers{
"Upgrade" => "websocket",
"Connection" => "Upgrade",
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
"Upgrade" => "websocket",
"Connection" => "Upgrade",
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version" => "13",
}
request = HTTP::Request.new("GET", "/1234", headers)
io_with_context = create_ws_request_and_return_io(handler, request)
io_with_context.to_s.should eq("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-Websocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")
io_with_context.to_s.should eq("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")
end
it "matches correct verb" do