Skip to content

Commit

Permalink
Windows support MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdogruyol committed Sep 30, 2024
1 parent 3243b8e commit 02bfcbe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
15 changes: 13 additions & 2 deletions spec/helpers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ describe "Macros" do
request = HTTP::Request.new("GET", "/")
response = call_request_on_app(request)
response.status_code.should eq(200)

response.headers["Content-Type"].should eq("application/octet-stream")
response.headers["Content-Length"].should eq("18")

{% if flag?(:windows) %}
response.headers["Content-Length"].should eq("19")
{% else %}
response.headers["Content-Length"].should eq("18")
{% end %}
end

it "sends file with given path and given mime-type" do
Expand All @@ -119,7 +125,12 @@ describe "Macros" do
response = call_request_on_app(request)
response.status_code.should eq(200)
response.headers["Content-Type"].should eq("image/jpeg")
response.headers["Content-Length"].should eq("18")

{% if flag?(:windows) %}
response.headers["Content-Length"].should eq("19")
{% else %}
response.headers["Content-Length"].should eq("18")
{% end %}
end

it "sends file with binary stream" do
Expand Down
9 changes: 7 additions & 2 deletions spec/run_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ describe "Run" do
Kemal.config.env = "test"
Kemal.run do |config|
server = config.server.not_nil!
server.bind_tcp "127.0.0.1", 3000, reuse_port: true
server.bind_tcp "0.0.0.0", 3001, reuse_port: true
{% if flag?(:windows) %}
server.bind_tcp "127.0.0.1", 3000
{% else %}
server.bind_tcp "127.0.0.1", 3000, reuse_port: true
server.bind_tcp "0.0.0.0", 3001, reuse_port: true
{% end %}
end
CR
end
Expand Down
6 changes: 5 additions & 1 deletion spec/view_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ describe "Views" do
end
request = HTTP::Request.new("GET", "/view/world")
client_response = call_request_on_app(request)
client_response.body.strip.should eq("<html>Hello world\n</html>")
{% if flag?(:windows) %}
client_response.body.strip.should eq("<html>Hello world\r\n</html>")
{% else %}
client_response.body.strip.should eq("<html>Hello world\n</html>")
{% end %}
end

it "renders layout" do
Expand Down
6 changes: 5 additions & 1 deletion src/kemal/config.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Kemal
VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
{% if flag?(:windows) %}
VERSION = {{ `shards version`.chomp.stringify }}
{% else %}
VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
{% end %}

# Stores all the configuration options for a Kemal application.
# It's a singleton and you can access it like.
Expand Down
2 changes: 1 addition & 1 deletion src/kemal/static_file_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Kemal
return
end

expanded_path = File.expand_path(request_path, "/")
expanded_path = request_path
is_dir_path = if original_path.ends_with?('/') && !expanded_path.ends_with? '/'
expanded_path = expanded_path + '/'
true
Expand Down

0 comments on commit 02bfcbe

Please sign in to comment.