-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lost
committed
May 2, 2024
0 parents
commit e205725
Showing
15 changed files
with
873 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This configuration file was generated by `ameba --gen-config` | ||
# on 2024-05-02 00:15:18 UTC using Ameba version 1.6.1. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the reported problems are removed from the code base. | ||
|
||
# Problems found: 2 | ||
# Run `ameba --only Lint/DebugCalls` for details | ||
Lint/DebugCalls: | ||
Description: Disallows debug-related calls | ||
Excluded: | ||
- spec\puppy_spec.cr | ||
MethodNames: | ||
- p | ||
- p! | ||
- pp | ||
- pp! | ||
Enabled: true | ||
Severity: Warning | ||
|
||
# Problems found: 2 | ||
# Run `ameba --only Naming/TypeNames` for details | ||
Naming/TypeNames: | ||
Description: Enforces type names in camelcase manner | ||
Excluded: | ||
- src\puppy\lib_winhttp.cr | ||
Enabled: true | ||
Severity: Convention | ||
|
||
# Problems found: 1 | ||
# Run `ameba --only Metrics/CyclomaticComplexity` for details | ||
Metrics/CyclomaticComplexity: | ||
Description: Disallows methods with a cyclomatic complexity higher than `MaxComplexity` | ||
MaxComplexity: 10 | ||
Excluded: | ||
- src\puppy.cr | ||
Enabled: true | ||
Severity: Warning | ||
|
||
# Problems found: 24 | ||
# Run `ameba --only Naming/VariableNames` for details | ||
Naming/VariableNames: | ||
Description: Enforces variable names to be in underscored case | ||
Excluded: | ||
- src\puppy.cr | ||
Enabled: true | ||
Severity: Convention | ||
|
||
# Problems found: 1 | ||
# Run `ameba --only Style/WhileTrue` for details | ||
Style/WhileTrue: | ||
Description: Disallows while statements with a true literal as condition | ||
Excluded: | ||
- src\puppy.cr | ||
Enabled: true | ||
Severity: Convention |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*.cr] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
* text=auto eol=lf | ||
|
||
*.bat text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
|
||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Crystal CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
jobs: | ||
check_format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Crystal | ||
uses: crystal-lang/install-crystal@v1 | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
- name: Install dependencies | ||
run: shards install | ||
- name: Check format | ||
run: crystal tool format --check | ||
|
||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- {os: ubuntu-latest, crystal: latest} | ||
- {os: ubuntu-latest, crystal: nightly} | ||
- {os: macos-latest} | ||
- {os: windows-latest} | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Install Crystal | ||
uses: crystal-lang/install-crystal@v1 | ||
with: | ||
crystal: ${{ matrix.crystal }} | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
- name: Install dependencies | ||
run: shards install | ||
- name: Print crystal version | ||
run: crystal version | ||
- name: Run tests | ||
run: crystal spec --verbose --progress --time --stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/docs/ | ||
/lib/ | ||
/bin/ | ||
/.shards/ | ||
*.dwarf | ||
|
||
# Libraries don't need dependency lock | ||
# Dependencies will be locked in applications that use them | ||
/shard.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 lost <lost> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# puppy | ||
|
||
[API DOC](https://lost22git.github.io/puppy.cr) | ||
|
||
TODO: Write a description here | ||
|
||
## Installation | ||
|
||
1. Add the dependency to your `shard.yml`: | ||
|
||
```yaml | ||
dependencies: | ||
puppy: | ||
github: lost22git/puppy | ||
``` | ||
2. Run `shards install` | ||
|
||
## Usage | ||
|
||
```crystal | ||
require "puppy" | ||
``` | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Development | ||
|
||
TODO: Write development instructions here | ||
|
||
## Contributing | ||
|
||
1. Fork it (<https://github.com/lost22git/puppy/fork>) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request | ||
|
||
## Contributors | ||
|
||
- [lost](https://github.com/lost22git) - creator and maintainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set windows-shell := [ "nu", "-c" ] | ||
|
||
_default: | ||
@just --list | ||
|
||
clean: | ||
crystal clear_cache | ||
|
||
[windows] | ||
check *flags: | ||
./bin/ameba.exe {{ flags }} | ||
|
||
[unix] | ||
check *flags: | ||
./bin/ameba {{ flags }} | ||
|
||
docs *flags: | ||
crystal docs {{ flags }} | ||
|
||
test *spec_files: | ||
crystal spec --progress {{ spec_files }} | ||
|
||
build *flags: | ||
shards build --production --release --no-debug --verbose --progress --time {{ flags }} | ||
|
||
run *flags: | ||
shards run --error-trace --progress {{ flags }} | ||
|
||
exec exec_file *flags: | ||
crystal run --error-trace --progress {{ flags }} {{ exec_file }} | ||
|
||
bench bench_file *flags: | ||
crystal run --release --progress {{ flags }} {{ bench_file }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: puppy | ||
version: 0.1.0 | ||
|
||
authors: | ||
- lost <lost> | ||
|
||
crystal: '>= 1.12.1' | ||
|
||
license: MIT | ||
|
||
development_dependencies: | ||
ameba: | ||
github: crystal-ameba/ameba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require "./spec_helper" | ||
require "json" | ||
|
||
describe Puppy do | ||
it "gzip" do | ||
# curl -X GET "https://httpbin.org/gzip" -H "accept: application/json" | ||
# | ||
headers = HTTP::Headers.new | ||
headers["accept-encoding"] = "gzip" | ||
headers["content-type"] = "application/json" | ||
url = "https://httpbin.org/gzip" | ||
method = "GET" | ||
req = HTTP::Request.new method, url, headers: headers | ||
|
||
resp = Puppy.fetch req, 10.seconds | ||
JSON.parse(resp.body_io)["gzipped"].as_bool.should be_true | ||
end | ||
|
||
# Failed! | ||
# | ||
# trace: https://github.com/crystal-lang/crystal/issues/5221 | ||
# | ||
# it "deflate" do | ||
# # curl -X GET "https://httpbin.org/deflate" -H "accept: application/json" | ||
# # | ||
# headers = HTTP::Headers.new | ||
# headers["content-type"] = "application/json" | ||
# url = "https://httpbin.org/deflate" | ||
# method = "GET" | ||
# req = HTTP::Request.new method, url, headers: headers | ||
|
||
# resp = Puppy.fetch req, 10.seconds | ||
# JSON.parse(resp.body_io)["deflated"].as_bool.should be_true | ||
# end | ||
|
||
it "status code" do | ||
# curl -X GET "https://httpbin.org/status/444" -H "accept: text/plain" | ||
# | ||
headers = HTTP::Headers.new | ||
headers["accept-encoding"] = "gzip" | ||
url = "https://httpbin.org/status/444" | ||
method = "GET" | ||
req = HTTP::Request.new method, url, headers: headers | ||
|
||
resp = Puppy.fetch req, 10.seconds | ||
resp.status_code.should eq 444 | ||
end | ||
|
||
it "proxy" do | ||
# curl -X GET "https://httpbin.org/ip" -H "accept: application/json" | ||
# | ||
headers = HTTP::Headers.new | ||
headers["accept"] = "application/json" | ||
url = "https://httpbin.org/ip" | ||
method = "GET" | ||
req = HTTP::Request.new method, url, headers | ||
|
||
# proxy | ||
resp = Puppy.fetch req, 10.seconds, proxy_addr: URI.parse("http://localhost:55556") | ||
proxied_pub_ip = JSON.parse(resp.body_io)["origin"].as_s | ||
proxied_pub_ip.should_not be "" | ||
|
||
# no proxy | ||
resp = Puppy.fetch req, 10.seconds | ||
no_proxied_pub_ip = JSON.parse(resp.body_io)["origin"].as_s | ||
no_proxied_pub_ip.should_not be "" | ||
no_proxied_pub_ip.should_not eq proxied_pub_ip | ||
end | ||
|
||
it "user-agent" do | ||
# curl -X GET "https://httpbin.org/user-agent" -H "accept: application/json" | ||
# | ||
headers = HTTP::Headers.new | ||
headers["accept"] = "application/json" | ||
url = "https://httpbin.org/user-agent" | ||
method = "GET" | ||
req = HTTP::Request.new method, url, headers | ||
|
||
resp = Puppy.fetch req, 10.seconds | ||
ua = JSON.parse(resp.body_io)["user-agent"].as_s | ||
ua.should eq Puppy::UA | ||
|
||
# use custom UA | ||
headers["user-agent"] = ";-)" | ||
req = HTTP::Request.new method, url, headers | ||
|
||
resp = Puppy.fetch req, 10.seconds | ||
ua = JSON.parse(resp.body_io)["user-agent"].as_s | ||
ua.should eq ";-)" | ||
end | ||
|
||
it "large file download" do | ||
# curl -X GET "https://httpbin.org/bytes/100" -H "accept: application/octet-stream" | ||
# | ||
headers = HTTP::Headers.new | ||
headers["accept"] = "application/octet-stream" | ||
url = "https://httpbin.org/bytes/" + (10 * 1024 * 1024).to_s | ||
method = "GET" | ||
req = HTTP::Request.new method, url, headers | ||
|
||
resp = Puppy.fetch req, 10.seconds | ||
resp.body_io.getb_to_end.size.should eq(100 * 1024) # httpbin only generate up to 100KB data | ||
end | ||
|
||
# it "timeout" do | ||
# # curl -X GET "https://httpbin.org/delay/5" -H "accept: application/json" | ||
# # | ||
# headers = HTTP::Headers.new | ||
# headers["accept"] = "application/json" | ||
# url = "https://httpbin.org/delay/5" | ||
# method = "GET" | ||
# req = HTTP::Request.new method, url, headers | ||
|
||
# resp = Puppy.fetch req, 1.seconds | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "spec" | ||
require "../src/puppy" |
Oops, something went wrong.