Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Webless CI

on:
push:
branches: [main]
pull_request:
branches: "*"

jobs:
check_format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crystal-lang/install-crystal@v1
with:
crystal: latest
- run: shards install
- run: crystal tool format --check
- run: ./bin/ameba
specs:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
crystal: latest
- os: windows-latest
crystal: latest
- os: macos-latest
crystal: latest
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: crystal-lang/install-crystal@v1
with:
crystal: latest
- run: shards install --skip-executables --skip-postinstall
- run: crystal spec
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ license: MIT
development_dependencies:
ameba:
github: crystal-ameba/ameba
version: ~> 0.14.0
version: ~> 1.6.4
spectator:
gitlab: arctic-fox/spectator
version: ~> 0.10.3
version: ~> 0.12.0

2 changes: 1 addition & 1 deletion spec/webless/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Spectator.describe Webless::Client do
client.get("/foo")

expect(result).not_to be_nil
expect(result.not_nil!.request).to have_attributes(path: "/foo", method: "GET")
expect(result.as(HTTP::Server::Context).request).to have_attributes(path: "/foo", method: "GET")
end

it "handles cookies" do
Expand Down
17 changes: 15 additions & 2 deletions src/webless/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class Webless::Client < HTTP::Client
def initialize(@app, @host = Webless::DEFAULT_HOST)
end

# HACK: Something changed in Crystal 1.16 with how request.resource works,
# and now sometimes `path` here will be the whole URL.
private def new_request(method, path, headers, body : BodyType)
{% if compare_versions(Crystal::VERSION, "1.16.0") >= 0 %}
uri = URI.parse(path)
path = uri.path
uri.query.try do |query|
path += "?#{query}"
end
{% end %}
HTTP::Request.new(method, path, headers, body)
end

def exec_internal(request : HTTP::Request) : HTTP::Client::Response
@last_request = request
cookie_jar.for(uri_for_request(request)).add_request_headers(request.headers)
Expand All @@ -31,7 +44,7 @@ class Webless::Client < HTTP::Client
end

def last_request : HTTP::Request
@last_request.not_nil!
@last_request.as(HTTP::Request)
end

# Added because the URL is not accessible on the request
Expand All @@ -40,7 +53,7 @@ class Webless::Client < HTTP::Client
end

def last_response : HTTP::Client::Response
@last_response.not_nil!
@last_response.as(HTTP::Client::Response)
end

def clear_cookies
Expand Down
6 changes: 3 additions & 3 deletions src/webless/cookie_jar.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Webless::CookieJar
end

def get_cookie(name : String) : HTTP::Cookie
get_cookie?(name).not_nil!
get_cookie?(name).as(HTTP::Cookie)
end

def get_cookie?(name : String) : HTTP::Cookie?
Expand All @@ -51,8 +51,8 @@ class Webless::CookieJar
end

private def sort!
@cookies.sort do |a, b|
to_sortable(a) <=> to_sortable(b)
@cookies.sort do |a_cookie, b_cookie|
to_sortable(a_cookie) <=> to_sortable(b_cookie)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/webless/request_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class Webless::RequestBuilder
end

def build : HTTP::Request
path = @path.not_nil!
path = @path.to_s
path += "?#{params}" if !params.empty?
HTTP::Request.new(@method.not_nil!, path, @headers, body)
HTTP::Request.new(@method.to_s, path, @headers, body)
end

def clone : RequestBuilder
Expand Down