mirror of
https://github.com/edgurgel/httparrot
synced 2025-03-13 12:04:57 -04:00
mix format and replace certs
This commit is contained in:
parent
d2607766b0
commit
312b6723f3
22 changed files with 153 additions and 140 deletions
29
.travis.yml
29
.travis.yml
|
@ -1,29 +0,0 @@
|
|||
language: elixir
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- eduardo@gurgel.me
|
||||
cache:
|
||||
directories:
|
||||
- _build
|
||||
- deps
|
||||
sudo: false
|
||||
script: mix test
|
||||
matrix:
|
||||
include:
|
||||
- elixir: '1.7'
|
||||
otp_release: '19.3'
|
||||
- elixir: '1.7'
|
||||
otp_release: '20.3'
|
||||
- elixir: '1.7'
|
||||
otp_release: '21.0'
|
||||
- elixir: '1.8'
|
||||
otp_release: '20.3'
|
||||
- elixir: '1.8'
|
||||
otp_release: '21.0'
|
||||
- elixir: '1.8'
|
||||
otp_release: '22.0.1'
|
||||
- elixir: '1.15.8'
|
||||
otp_release: '25.3.2.12'
|
||||
- elixir: '1.16.3'
|
||||
otp_release: '26.2.5'
|
|
@ -14,4 +14,3 @@ config :httparrot,
|
|||
https_port: ssl_port,
|
||||
unix_socket: unix_socket,
|
||||
socket_path: System.get_env("SOCKET_PATH", "httparrot.sock")
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ defmodule HTTParrot do
|
|||
end
|
||||
|
||||
def init(_) do
|
||||
Supervisor.start_link([], [strategy: :one_for_one])
|
||||
Supervisor.start_link([], strategy: :one_for_one)
|
||||
end
|
||||
|
||||
def start(_type, _args) do
|
||||
|
@ -71,9 +71,9 @@ defmodule HTTParrot do
|
|||
:https,
|
||||
[
|
||||
port: https_port,
|
||||
cacertfile: priv_dir ++ '/ssl/server-ca.crt',
|
||||
certfile: priv_dir ++ '/ssl/server.crt',
|
||||
keyfile: priv_dir ++ '/ssl/server.key'
|
||||
cacertfile: priv_dir ++ ~c"/ssl/server-ca.crt",
|
||||
certfile: priv_dir ++ ~c"/ssl/server.crt",
|
||||
keyfile: priv_dir ++ ~c"/ssl/server.key"
|
||||
],
|
||||
%{env: %{dispatch: dispatch}}
|
||||
)
|
||||
|
|
|
@ -19,7 +19,11 @@ defmodule HTTParrot.RedirectHandler do
|
|||
def previously_existed(req, state), do: {true, req, state}
|
||||
|
||||
def moved_permanently(req, n) do
|
||||
host_url = IO.iodata_to_binary(:cowboy_req.uri(req, %{path: :undefined, qs: :undefined, fragment: :undefined}))
|
||||
host_url =
|
||||
IO.iodata_to_binary(
|
||||
:cowboy_req.uri(req, %{path: :undefined, qs: :undefined, fragment: :undefined})
|
||||
)
|
||||
|
||||
url = if n > 1, do: "/redirect/#{n - 1}", else: "/get"
|
||||
{{true, host_url <> url}, req, nil}
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ defmodule HTTParrot.StoreRequestHandler do
|
|||
{info, req} = GeneralRequestInfo.retrieve(req)
|
||||
key = :cowboy_req.binding(:key, req)
|
||||
HTTParrot.RequestStore.store(key, info)
|
||||
{'{"saved": "true"}', req, state}
|
||||
{~c'{"saved": "true"}', req, state}
|
||||
end
|
||||
|
||||
def post_binary(req, _state) do
|
||||
|
|
|
@ -31,13 +31,15 @@ defmodule HTTParrot.StreamBytesHandler do
|
|||
end
|
||||
|
||||
defp stream_response!(n, chunk_size, req) do
|
||||
req = :cowboy_req.stream_reply(200, %{ "content-type" => "application/octet-stream" }, req)
|
||||
req = :cowboy_req.stream_reply(200, %{"content-type" => "application/octet-stream"}, req)
|
||||
|
||||
Stream.repeatedly(fn -> :rand.uniform(255) end)
|
||||
|> Stream.take(n)
|
||||
|> Enum.chunk_every(chunk_size, chunk_size, [])
|
||||
|> Enum.each(fn chunk ->
|
||||
:cowboy_req.stream_body(List.to_string(chunk), :nofin, req)
|
||||
end)
|
||||
|
||||
:cowboy_req.stream_body("", :fin, req)
|
||||
req
|
||||
end
|
||||
|
|
|
@ -25,11 +25,13 @@ defmodule HTTParrot.StreamHandler do
|
|||
|
||||
def get_json(req, n) do
|
||||
{info, req} = GeneralRequestInfo.retrieve(req)
|
||||
req = :cowboy_req.stream_reply(200, %{ "content-type" => "application/json" }, req)
|
||||
req = :cowboy_req.stream_reply(200, %{"content-type" => "application/json"}, req)
|
||||
|
||||
Enum.each(0..(n - 1), fn i ->
|
||||
body = JSX.encode!([id: i] ++ info)
|
||||
:cowboy_req.stream_body(body, :nofin, req)
|
||||
end)
|
||||
|
||||
:cowboy_req.stream_body("", :fin, req)
|
||||
{:stop, req, nil}
|
||||
end
|
||||
|
|
|
@ -1,16 +1,27 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICeDCCAeGgAwIBAgIJAOvpU0y2e5J4MA0GCSqGSIb3DQEBBQUAMFUxCzAJBgNV
|
||||
BAYTAlVTMQ4wDAYDVQQIDAVUZXhhczETMBEGA1UECgwKTmluZSBOaW5lczEPMA0G
|
||||
A1UECwwGQ293Ym95MRAwDgYDVQQDDAdST09UIENBMB4XDTEzMDIyODA1MTAwMVoX
|
||||
DTMzMDIyMzA1MTAwMVowVTELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVRleGFzMRMw
|
||||
EQYDVQQKDApOaW5lIE5pbmVzMQ8wDQYDVQQLDAZDb3dib3kxEDAOBgNVBAMMB1JP
|
||||
T1QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMzmY7Us06yjyUbpqwPx
|
||||
Iv+xh/g3V7we07ClC9GEYnvr3OQvdA1jFEHccMBUUjRoQ8DPd6uSyK5UkixABs08
|
||||
Tt5B3VsnGKr0DIN+IO4SN2PkmBqIU/BN3KdcwN65YNr3iM0KsKWeFtAZdYx4CakX
|
||||
7REbO0wjK20AH3xSBn3uFGiBAgMBAAGjUDBOMB0GA1UdDgQWBBRKfZ8KF2jlLBDm
|
||||
NL6IuEuGY0pdbzAfBgNVHSMEGDAWgBRKfZ8KF2jlLBDmNL6IuEuGY0pdbzAMBgNV
|
||||
HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAG1I0kBxXiLkM1b7rl2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,8 +4,8 @@ defmodule HTTParrot.Base64HandlerTest do
|
|||
import HTTParrot.Base64Handler
|
||||
|
||||
setup do
|
||||
new :cowboy_req
|
||||
on_exit fn -> unload() end
|
||||
new(:cowboy_req)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
@ -4,32 +4,33 @@ defmodule HTTParrot.BasicAuthHandlerTest do
|
|||
import HTTParrot.BasicAuthHandler
|
||||
|
||||
setup do
|
||||
new :cowboy_req
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(:cowboy_req)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "is_authorized returns true if user and passwd match" do
|
||||
expect(:cowboy_req, :binding, [{[:user, :req1], :user},
|
||||
{[:passwd, :req1], :passwd}])
|
||||
expect(:cowboy_req, :binding, [{[:user, :req1], :user}, {[:passwd, :req1], :passwd}])
|
||||
expect(:cowboy_req, :parse_header, [{["authorization", :req1], {:basic, :user, :passwd}}])
|
||||
|
||||
assert is_authorized(:req1, :state) == {true, :req1, :user}
|
||||
|
||||
assert validate :cowboy_req
|
||||
assert validate JSX
|
||||
assert validate(:cowboy_req)
|
||||
assert validate(JSX)
|
||||
end
|
||||
|
||||
test "is_authorized returns false if user and passwd doesn't match" do
|
||||
expect(:cowboy_req, :binding, [{[:user, :req1], :user},
|
||||
{[:passwd, :req1], :passwd}])
|
||||
expect(:cowboy_req, :parse_header, [{["authorization", :req1], {:basic, :not_the_user, :passwd}}])
|
||||
test "is_authorized returns false if user and passwd doesnt match" do
|
||||
expect(:cowboy_req, :binding, [{[:user, :req1], :user}, {[:passwd, :req1], :passwd}])
|
||||
|
||||
expect(:cowboy_req, :parse_header, [
|
||||
{["authorization", :req1], {:basic, :not_the_user, :passwd}}
|
||||
])
|
||||
|
||||
assert is_authorized(:req1, :state) == {{false, "Basic realm=\"Fake Realm\""}, :req1, :state}
|
||||
|
||||
assert validate :cowboy_req
|
||||
assert validate JSX
|
||||
assert validate(:cowboy_req)
|
||||
assert validate(JSX)
|
||||
end
|
||||
|
||||
test "returns user and if it's authenticated" do
|
||||
|
@ -37,6 +38,6 @@ defmodule HTTParrot.BasicAuthHandlerTest do
|
|||
|
||||
assert get_json(:req1, :user) == {:json, :req1, nil}
|
||||
|
||||
assert validate JSX
|
||||
assert validate(JSX)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ defmodule HTTParrot.CacheHandlerTest do
|
|||
import HTTParrot.CacheHandler
|
||||
|
||||
setup do
|
||||
new HTTParrot.GeneralRequestInfo
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(HTTParrot.GeneralRequestInfo)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ defmodule HTTParrot.CacheHandlerTest do
|
|||
|
||||
assert get_json(:req1, :state) == {:json, :req2, :state}
|
||||
|
||||
assert validate HTTParrot.GeneralRequestInfo
|
||||
assert validate JSX
|
||||
assert validate(HTTParrot.GeneralRequestInfo)
|
||||
assert validate(JSX)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ defmodule HTTParrot.DeflateHandlerTest do
|
|||
import HTTParrot.DeflateHandler
|
||||
|
||||
setup do
|
||||
new HTTParrot.GeneralRequestInfo
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(HTTParrot.GeneralRequestInfo)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
@ -16,15 +16,15 @@ defmodule HTTParrot.DeflateHandlerTest do
|
|||
expect(JSX, :prettify!, [{[:json], "json"}])
|
||||
expect(:cowboy_req, :set_resp_header, 3, :req3)
|
||||
|
||||
opened_zlib = :zlib.open
|
||||
opened_zlib = :zlib.open()
|
||||
:zlib.deflateInit(opened_zlib)
|
||||
body = :zlib.deflate(opened_zlib, "json", :finish)
|
||||
:zlib.deflateEnd(opened_zlib)
|
||||
|
||||
assert get_json(:req1, :state) == {body, :req3, :state}
|
||||
|
||||
assert validate HTTParrot.GeneralRequestInfo
|
||||
assert validate JSX
|
||||
assert validate :cowboy_req
|
||||
assert validate(HTTParrot.GeneralRequestInfo)
|
||||
assert validate(JSX)
|
||||
assert validate(:cowboy_req)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,10 @@ defmodule HTTParrot.DeleteHandlerTest do
|
|||
import HTTParrot.DeleteHandler
|
||||
|
||||
setup do
|
||||
new :cowboy_req
|
||||
new HTTParrot.GeneralRequestInfo
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(:cowboy_req)
|
||||
new(HTTParrot.GeneralRequestInfo)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
@ -18,8 +18,8 @@ defmodule HTTParrot.DeleteHandlerTest do
|
|||
|
||||
assert delete_resource(:req1, :state) == {true, :req3, :state}
|
||||
|
||||
assert validate :cowboy_req
|
||||
assert validate HTTParrot.GeneralRequestInfo
|
||||
assert validate JSX
|
||||
assert validate(:cowboy_req)
|
||||
assert validate(HTTParrot.GeneralRequestInfo)
|
||||
assert validate(JSX)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ defmodule HTTParrot.GetHandlerTest do
|
|||
import HTTParrot.GetHandler
|
||||
|
||||
setup do
|
||||
new HTTParrot.GeneralRequestInfo
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(HTTParrot.GeneralRequestInfo)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ defmodule HTTParrot.GetHandlerTest do
|
|||
|
||||
assert get_json(:req1, :state) == {:json, :req2, :state}
|
||||
|
||||
assert validate HTTParrot.GeneralRequestInfo
|
||||
assert validate JSX
|
||||
assert validate(HTTParrot.GeneralRequestInfo)
|
||||
assert validate(JSX)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ defmodule HTTParrot.GzipHandlerTest do
|
|||
import HTTParrot.GzipHandler
|
||||
|
||||
setup do
|
||||
new HTTParrot.GeneralRequestInfo
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(HTTParrot.GeneralRequestInfo)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
@ -20,8 +20,8 @@ defmodule HTTParrot.GzipHandlerTest do
|
|||
|
||||
assert get_json(:req1, :state) == {body, :req3, :state}
|
||||
|
||||
assert validate HTTParrot.GeneralRequestInfo
|
||||
assert validate JSX
|
||||
assert validate :cowboy_req
|
||||
assert validate(HTTParrot.GeneralRequestInfo)
|
||||
assert validate(JSX)
|
||||
assert validate(:cowboy_req)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,10 +11,10 @@ defmodule HTTParrotTest do
|
|||
|
||||
test "'prettify_json' prettifies body response if it's a JSON" do
|
||||
expect(:cowboy_req, :reply, [
|
||||
{[:status, %{"content-length" => '14'}, "{\n \"a\": \"b\"\n}", :req1], :req2}
|
||||
{[:status, %{"content-length" => ~c"14"}, "{\n \"a\": \"b\"\n}", :req1], :req2}
|
||||
])
|
||||
|
||||
assert prettify_json(:status, %{"content-length" => '12'}, "{\"a\":\"b\"}", :req1) == :req2
|
||||
assert prettify_json(:status, %{"content-length" => ~c"12"}, "{\"a\":\"b\"}", :req1) == :req2
|
||||
assert validate(:cowboy_req)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
defmodule HTTParrot.RequestStoreTest do
|
||||
alias HTTParrot.RequestStore
|
||||
use ExUnit.Case
|
||||
|
||||
test "save, retrieve, clear" do
|
||||
request = %{req: 1}
|
||||
RequestStore.clear(:test)
|
||||
RequestStore.store(:test, request)
|
||||
assert RequestStore.retrieve(:test) == [request]
|
||||
RequestStore.clear(:test)
|
||||
RequestStore.clear(:test)
|
||||
assert RequestStore.retrieve(:test) == []
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ defmodule HTTParrot.RetrieveRequestHandlerTests do
|
|||
|
||||
setup do
|
||||
HTTParrot.RequestStore.clear(:test)
|
||||
on_exit fn -> unload() end
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
@ -12,15 +12,15 @@ defmodule HTTParrot.StoreRequestHandlerTests do
|
|||
test "store a request" do
|
||||
expect(:cowboy_req, :binding, [:key, :req1], :test)
|
||||
expect(HTTParrot.GeneralRequestInfo, :retrieve, 1, {:info, :req1})
|
||||
assert get(:req1, :state) == {'{"saved": "true"}', :req1, :state}
|
||||
assert get(:req1, :state) == {~c'{"saved": "true"}', :req1, :state}
|
||||
assert HTTParrot.RequestStore.retrieve(:test) == [:info]
|
||||
end
|
||||
|
||||
test "store multiple requests" do
|
||||
expect(:cowboy_req, :binding, [:key, :req1], :test)
|
||||
expect(HTTParrot.GeneralRequestInfo, :retrieve, 1, {:info, :req1})
|
||||
assert get(:req1, :state) == {'{"saved": "true"}', :req1, :state}
|
||||
assert get(:req2, :state) == {'{"saved": "true"}', :req1, :state}
|
||||
assert get(:req1, :state) == {~c'{"saved": "true"}', :req1, :state}
|
||||
assert get(:req2, :state) == {~c'{"saved": "true"}', :req1, :state}
|
||||
assert HTTParrot.RequestStore.retrieve(:test) == [:info, :info]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ defmodule HTTParrot.UserAgentHandlerTest do
|
|||
import HTTParrot.UserAgentHandler
|
||||
|
||||
setup do
|
||||
new :cowboy_req
|
||||
new JSX
|
||||
on_exit fn -> unload() end
|
||||
new(:cowboy_req)
|
||||
new(JSX)
|
||||
on_exit(fn -> unload() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ defmodule HTTParrot.UserAgentHandlerTest do
|
|||
|
||||
assert get_json(:req1, :state) == {:json, :req1, :state}
|
||||
|
||||
assert validate :cowboy_req
|
||||
assert validate JSX
|
||||
assert validate(:cowboy_req)
|
||||
assert validate(JSX)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue