http_fp 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/README.md +63 -10
- data/http_fp.gemspec +1 -2
- data/lib/http_fp.rb +23 -22
- data/lib/http_fp/curl.rb +7 -6
- data/lib/http_fp/httpie.rb +5 -4
- data/lib/http_fp/operators.rb +1 -3
- data/lib/http_fp/rack.rb +30 -29
- data/lib/http_fp/utils.rb +17 -18
- data/lib/http_fp/version.rb +1 -1
- data/test/http_fp/httpie_test.rb +11 -11
- data/test/http_fp/rack_test.rb +11 -27
- data/test/http_fp_test.rb +3 -4
- metadata +4 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3b73d8ca4247f899573be513abede0492ba73f7cb218af122722b6cf98d26bb
|
4
|
+
data.tar.gz: 6fdc1f65704f8c26814ea824707a4f20545b8bada1365ae424095b0af0afbb7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f62b4abfc4d345d0c04031291c04f90165b3cf72c84aee63c66d9fa92413f711ec5bce0374ab114e4b78d9045658f651bfedf533fa0a381777eeb160df394c2b
|
7
|
+
data.tar.gz: 47a8d5fc2ff42cfeefded5c8bf36ccfc8b1499bff2b1592cca62d3b6469375880081aa33c46e862a7de0f62437e6e798312fb06e7e648dc495c98f1c7638f803
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6
|
data/README.md
CHANGED
@@ -25,12 +25,12 @@ Here's an example of a request:
|
|
25
25
|
:body=>""}
|
26
26
|
```
|
27
27
|
|
28
|
-
To build that request you can use builder functions and the function composition operator ([
|
28
|
+
To build that request you can use builder functions and the function composition operator ([`>>`](https://docs.ruby-lang.org/en/2.6.0/Proc.html#method-i-3E-3E)). Every builder function adds values to the response object. Example:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
query = verb.("get")
|
32
|
-
with_path.("/users/martinos/repos")
|
33
|
-
with_host.("https://api.github.com")
|
31
|
+
query = verb.("get") >>
|
32
|
+
with_path.("/users/martinos/repos") >>
|
33
|
+
with_host.("https://api.github.com") >>
|
34
34
|
add_headers.(json_headers)
|
35
35
|
```
|
36
36
|
The `query` variable is a builder function that is created by combining multiple builder functions together.
|
@@ -51,7 +51,6 @@ pp empty_req
|
|
51
51
|
:body=>""}
|
52
52
|
```
|
53
53
|
|
54
|
-
<<<<<<< HEAD
|
55
54
|
We apply the `empty_req` to the query that we've built.
|
56
55
|
```ruby
|
57
56
|
pp query.(empty_req)
|
@@ -86,16 +85,70 @@ HttpFp::NetHttp.server.(query.(empty_req))
|
|
86
85
|
|
87
86
|
```
|
88
87
|
|
89
|
-
You can also use the pipe operator ([`>>+`](https://github.com/martinos/http_fp/blob/master/lib/http_fp/operators.rb#L8)) and the run function. The `run_` function takes a function as parameter and applies the `empty_req` to it.
|
90
|
-
|
91
|
-
Here is it's definition:
|
92
88
|
```ruby
|
93
|
-
|
89
|
+
(query >> HttpFp::NetHttp.server).(empty_req)
|
94
90
|
```
|
95
91
|
|
92
|
+
Since a "server" is just a function that takes an HTTP request and returns an HTTP response, instead of using Net::Http interface you can use the `HttpFp::Rack.server` function that takes a rack app as parameter.
|
93
|
+
|
96
94
|
```run
|
97
|
-
query
|
95
|
+
query >> HttpFp::Rack.server.(Rails.application)
|
96
|
+
```
|
97
|
+
|
98
|
+
## Middlewares
|
99
|
+
|
100
|
+
Since we are using composable functions to build our request and to query the web server, it's very easy to create our own "middlewares".
|
101
|
+
|
102
|
+
If we want to all the request and the response we can create a simple function such as:
|
103
|
+
|
104
|
+
```
|
105
|
+
debug_fn = -> print, fn, input {
|
106
|
+
print.("Input: \n")
|
107
|
+
print.(input.to_s)
|
108
|
+
output = fn.(input)
|
109
|
+
print.("Output: \n")
|
110
|
+
print.(output)
|
111
|
+
output
|
112
|
+
}.curry
|
113
|
+
|
114
|
+
```
|
115
|
+
|
116
|
+
the `print` param is a function that prints an object.
|
117
|
+
|
118
|
+
```
|
119
|
+
printer = -> a { print a; a }
|
120
|
+
query >> debug_fn.(printer).(HttpFp::NetHttp.server)
|
121
|
+
```
|
122
|
+
|
123
|
+
of course you can change the printer to print to the log file.
|
124
|
+
|
98
125
|
```
|
126
|
+
printer = -> a { logger.debug(a) ; a }
|
127
|
+
```
|
128
|
+
|
129
|
+
### Curl, Httpie output
|
130
|
+
|
131
|
+
If you want to generate documentation with curl commands you can use a simple function such as:
|
132
|
+
|
133
|
+
```
|
134
|
+
curl = -> a { puts HttpFp::Curl.req.(a) ; a }.curry
|
135
|
+
```
|
136
|
+
|
137
|
+
Then you can use it with the query and the server function.
|
138
|
+
|
139
|
+
```run
|
140
|
+
query >> curl >> HttpFp::NetHttp.server
|
141
|
+
```
|
142
|
+
|
143
|
+
This will output:
|
144
|
+
|
145
|
+
```
|
146
|
+
curl -X 'GET' 'https://api.github.com/users/martinos/repos?' \
|
147
|
+
-H 'accept: application/json' \
|
148
|
+
-H 'Content-Type: application/json' \
|
149
|
+
-H 'user-agent: ruby net/http'
|
150
|
+
```
|
151
|
+
|
99
152
|
|
100
153
|
|
101
154
|
## Contributing
|
data/http_fp.gemspec
CHANGED
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "minitest"
|
23
23
|
spec.add_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_dependency "rack"
|
25
|
-
spec.add_dependency "
|
26
|
-
spec.add_dependency "superators19"
|
25
|
+
spec.add_dependency "fn_reader"
|
27
26
|
end
|
data/lib/http_fp.rb
CHANGED
@@ -1,42 +1,43 @@
|
|
1
|
-
require "
|
1
|
+
require "fn_reader"
|
2
|
+
require "uri"
|
3
|
+
require "base64"
|
2
4
|
require "http_fp/version"
|
3
|
-
require
|
4
|
-
require 'uri'
|
5
|
-
require 'base64'
|
5
|
+
require "http_fp/utils"
|
6
6
|
|
7
7
|
module HttpFp
|
8
8
|
include Utils
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
fn_reader :verb, :with_host, :with_path, :with_query, :withUri,
|
11
|
+
:with_json, :with_headers, :add_headers, :fetch, :to_curl,
|
12
|
+
:out_curl, :json_resp, :to_uri, :empty_req, :json_headers,
|
13
|
+
:with_basic_auth, :run_
|
14
14
|
|
15
|
-
@@empty_req = {proto: "HTTP/1.1", host: "http://example.com", path: "/", query: {}, header: {}, method: "GET", body: ""}
|
16
|
-
@@empty_resp = {status: nil, header: {}, body: {}}
|
15
|
+
@@empty_req = { proto: "HTTP/1.1", host: "http://example.com", path: "/", query: {}, header: {}, method: "GET", body: "" }
|
16
|
+
@@empty_resp = { status: nil, header: {}, body: {} }
|
17
17
|
|
18
18
|
@@run_ = -> fn { fn.(@@empty_req) } # underscore because run conflicts with run fn in minitest
|
19
|
-
@@verb = -> verb, req { req.merge({method: verb.to_s.upcase}) }.curry
|
19
|
+
@@verb = -> verb, req { req.merge({ method: verb.to_s.upcase }) }.curry
|
20
20
|
@@with_host = -> host, req { req[:host] = host; req }.curry
|
21
21
|
@@with_path = -> path, req { req[:path] = path; req }.curry
|
22
|
-
@@with_query = -> params, req { req[:query] = params
|
22
|
+
@@with_query = -> params, req { req[:query] = params; req }.curry
|
23
23
|
@@with_json = -> hash, req { req[:body] = hash.to_json; req }.curry
|
24
|
-
@@with_headers = -> header, req { req[:header] = header
|
24
|
+
@@with_headers = -> header, req { req[:header] = header; req }.curry
|
25
25
|
@@add_headers = -> header, req { req[:header].merge!(header); req }.curry
|
26
|
-
@@with_basic_auth = -> user_name, pwd, req do
|
26
|
+
@@with_basic_auth = -> user_name, pwd, req do
|
27
27
|
encoded = Base64.strict_encode64("#{user_name}:#{pwd}")
|
28
|
-
req
|
28
|
+
req.then(&add_headers.({ "Authorization" => "Basic #{encoded}" }))
|
29
29
|
end.curry
|
30
30
|
|
31
|
-
@@json_resp = Utils.at.(:body)
|
32
|
-
@@print = -> a { $stdout.puts a.pretty_inspect
|
31
|
+
@@json_resp = Utils.at.(:body) >> Utils.parse_json
|
32
|
+
@@print = -> a { $stdout.puts a.pretty_inspect; a }
|
33
33
|
@@to_uri = -> req {
|
34
34
|
uri = URI(req.fetch(:host))
|
35
35
|
req[:query] && uri.query = URI.encode_www_form(req[:query])
|
36
36
|
uri.path = req[:path]
|
37
|
-
uri
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
uri
|
38
|
+
}
|
39
|
+
@@json_headers =
|
40
|
+
{ "accept" => "application/json",
|
41
|
+
"Content-Type" => "application/json",
|
42
|
+
"user-agent" => "paw/3.0.11 (macintosh; os x/10.11.6) gcdhttprequest" }
|
42
43
|
end
|
data/lib/http_fp/curl.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "net/http"
|
2
|
+
require "http_fp"
|
3
3
|
|
4
4
|
module HttpFp::Curl
|
5
5
|
include HttpFp
|
6
6
|
|
7
|
-
|
7
|
+
fn_reader :print_curl, :req
|
8
8
|
|
9
9
|
@@req = -> req {
|
10
10
|
first_part = %{curl -X '#{req[:method]}' '#{HttpFp::to_uri.(req).to_s}' #{req[:header].map(&@@header_to_curl).join(" ")}}
|
@@ -15,7 +15,8 @@ module HttpFp::Curl
|
|
15
15
|
end
|
16
16
|
}
|
17
17
|
@@header_to_curl = -> a {
|
18
|
-
"\\\n -H '#{a[0]}: #{a[1]}'"
|
19
|
-
|
20
|
-
|
18
|
+
"\\\n -H '#{a[0]}: #{a[1]}'"
|
19
|
+
}
|
20
|
+
|
21
|
+
@@print_curl = -> req { $stdout.puts(to_curl.(req)); req }.curry
|
21
22
|
end
|
data/lib/http_fp/httpie.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "net/http"
|
2
|
+
require "http_fp"
|
3
3
|
|
4
4
|
module HttpFp::Httpie
|
5
5
|
include HttpFp
|
6
6
|
|
7
|
-
|
7
|
+
fn_reader :print_curl, :req
|
8
8
|
|
9
9
|
@@req = -> req {
|
10
10
|
first_part = %{http #{req[:method]} '#{HttpFp::to_uri.(req).to_s}' #{req[:header].map(&@@header_to_httpie).join(" ")}}
|
@@ -15,5 +15,6 @@ module HttpFp::Httpie
|
|
15
15
|
end
|
16
16
|
}
|
17
17
|
@@header_to_httpie = -> a {
|
18
|
-
|
18
|
+
"\\\n '#{a[0]}: #{a[1]}'"
|
19
|
+
}
|
19
20
|
end
|
data/lib/http_fp/operators.rb
CHANGED
data/lib/http_fp/rack.rb
CHANGED
@@ -1,52 +1,53 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'pp'
|
1
|
+
require "http_fp"
|
2
|
+
require "pp"
|
4
3
|
#
|
5
4
|
# https://www.diffchecker.com/ihCGIKyG
|
6
5
|
|
7
6
|
module HttpFp::Rack
|
8
|
-
|
7
|
+
fn_reader :to_env, :server, :rack_resp_to_resp
|
9
8
|
|
10
|
-
@@server = -> rack { to_env
|
9
|
+
@@server = -> rack { to_env >> rack.method(:call) >> rack_resp_to_resp }
|
11
10
|
@@to_env = -> request {
|
12
11
|
session ||= {}
|
13
12
|
session_options ||= {}
|
14
13
|
|
15
|
-
uri = request
|
14
|
+
uri = request.then(&HttpFp.to_uri)
|
16
15
|
header = (request[:header] || {}).dup
|
17
|
-
body = request[:body] ||
|
16
|
+
body = request[:body] || ""
|
18
17
|
|
19
|
-
content_type_key, val = header.detect { |key, val| puts key; key.downcase == "content-type"}
|
18
|
+
content_type_key, val = header.detect { |key, val| puts key; key.downcase == "content-type" }
|
20
19
|
env = {
|
21
20
|
# CGI variables specified by Rack
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
"REQUEST_METHOD" => request[:method].to_s.upcase,
|
22
|
+
"CONTENT_TYPE" => header.delete(content_type_key),
|
23
|
+
"CONTENT_LENGTH" => body.bytesize,
|
24
|
+
"PATH_INFO" => uri.path,
|
25
|
+
"QUERY_STRING" => uri.query || "",
|
26
|
+
"SERVER_NAME" => uri.host,
|
27
|
+
"SERVER_PORT" => uri.port,
|
28
|
+
"SCRIPT_NAME" => "",
|
30
29
|
}
|
31
30
|
|
32
|
-
env[
|
31
|
+
env["HTTP_AUTHORIZATION"] = "Basic " + [uri.userinfo].pack("m").delete("\r\n") if uri.userinfo
|
33
32
|
|
34
33
|
# Rack-specific variables
|
35
|
-
env[
|
36
|
-
env[
|
37
|
-
env[
|
38
|
-
env[
|
39
|
-
env[
|
40
|
-
env[
|
41
|
-
env[
|
42
|
-
|
43
|
-
header.each { |k, v| env["HTTP_#{k.tr(
|
34
|
+
env["rack.input"] = StringIO.new(body)
|
35
|
+
env["rack.errors"] = $stderr
|
36
|
+
env["rack.version"] = ::Rack::VERSION
|
37
|
+
env["rack.url_scheme"] = uri.scheme
|
38
|
+
env["rack.run_once"] = true
|
39
|
+
env["rack.session"] = session
|
40
|
+
env["rack.session.options"] = session_options
|
41
|
+
|
42
|
+
header.each { |k, v| env["HTTP_#{k.tr("-", "_").upcase}"] = v }
|
44
43
|
env
|
45
44
|
}
|
46
45
|
|
47
|
-
@@rack_resp_to_resp = -> resp {
|
48
|
-
|
49
|
-
|
46
|
+
@@rack_resp_to_resp = -> resp {
|
47
|
+
{ status: resp[0],
|
48
|
+
header: resp[1],
|
49
|
+
body: @@body_from_rack_response.(resp[2]) }
|
50
|
+
}
|
50
51
|
|
51
52
|
@@body_from_rack_response = -> response {
|
52
53
|
body = ""
|
data/lib/http_fp/utils.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require 'http_fp/operators'
|
5
|
-
require 'yaml'
|
1
|
+
require "json"
|
2
|
+
require "pp"
|
3
|
+
require "yaml"
|
6
4
|
|
7
5
|
module Utils
|
8
|
-
|
9
|
-
:record, :player, :count_by, :cache, :red, :time,
|
6
|
+
fn_reader :parse_json, :debug, :at, :retry_fn,
|
7
|
+
:record, :player, :count_by, :cache, :red, :time,
|
10
8
|
:expired, :apply, :and_then, :default, :map, :get, :try
|
11
9
|
|
12
10
|
@@parse_json = JSON.method(:parse)
|
13
|
-
@@debug = -> print, a, b { print.(a)
|
11
|
+
@@debug = -> print, a, b { print.(a); print.(b.to_s); b }.curry
|
14
12
|
@@at = -> key, hash { hash[key] }.curry
|
15
13
|
@@red = -> a { "\033[31m#{a}\033[0m" }
|
16
14
|
# ( a -> b ) -> a -> b
|
17
|
-
@@try = -> f, a { a.nil? ?
|
15
|
+
@@try = -> f, a { a.nil? ? nil : f.(a) }.curry
|
18
16
|
@@retry_fn = -> fn, a {
|
19
17
|
begin
|
20
18
|
fn.(a)
|
@@ -30,33 +28,34 @@ module Utils
|
|
30
28
|
}.curry
|
31
29
|
@@play = -> filename, _params { YAML.load(File.read(filename)) }.curry
|
32
30
|
# (Float -> String -> Bool) -> String -> (a -> b) -> b
|
33
|
-
@@cache
|
34
|
-
if expired.(filename)
|
31
|
+
@@cache = -> expired, filename, fn, param {
|
32
|
+
if expired.(filename)
|
35
33
|
@@record.(filename).(fn.(param))
|
36
34
|
else
|
37
35
|
puts "reading from cache"
|
38
36
|
@@play.(filename).(nil)
|
39
37
|
end
|
40
38
|
}.curry
|
41
|
-
@@expired = -> sec, a { !
|
42
|
-
@@count_by = -> fn, a {
|
43
|
-
a.inject({}) do |res, a|
|
39
|
+
@@expired = -> sec, a { !File.exist?(a) || (Time.now - File.mtime(a)) > sec }.curry
|
40
|
+
@@count_by = -> fn, a {
|
41
|
+
a.inject({}) do |res, a|
|
44
42
|
by = fn.(a)
|
45
43
|
res[by] ||= 0
|
46
44
|
res[by] += 1
|
47
45
|
res
|
48
46
|
end
|
49
47
|
}.curry
|
50
|
-
|
48
|
+
|
51
49
|
# (String -> String) -> String -> ( a -> b ) -> a -> b
|
52
50
|
@@time = -> print, msg, fn, a {
|
53
|
-
start_time = Time.now
|
51
|
+
start_time = Time.now
|
54
52
|
res = fn.(a)
|
55
53
|
print.("Time duration for #{msg} = #{Time.now - start_time}")
|
56
|
-
res
|
54
|
+
res
|
55
|
+
}.curry
|
57
56
|
@@apply = -> method, a { a.send(method) }.curry
|
58
57
|
@@default = -> default, a { a.nil? ? default : a }.curry
|
59
|
-
@@and_then = -> f
|
58
|
+
@@and_then = -> f, a { a.nil? ? nil : f.(a) }.curry
|
60
59
|
@@map = -> f, enum { enum.map(&f) }.curry
|
61
60
|
@@at = -> key, hash { hash; hash[key] }.curry
|
62
61
|
@@get = -> method, obj { obj.send(method) }.curry
|
data/lib/http_fp/version.rb
CHANGED
data/test/http_fp/httpie_test.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "minitest_helper"
|
2
|
+
require "http_fp"
|
3
|
+
require "http_fp/rack"
|
4
|
+
require "http_fp/httpie"
|
5
5
|
|
6
6
|
class HttpFp::CurlTest < Minitest::Test
|
7
7
|
include HttpFp
|
8
8
|
|
9
|
-
def setup
|
10
|
-
@curl = verb.("GET")
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def setup
|
10
|
+
@curl = (verb.("GET") >>
|
11
|
+
with_path.("/coucou") >>
|
12
|
+
with_headers.(json_headers) >>
|
13
|
+
with_host.("https://api.github.com") >>
|
14
|
+
with_json.({ user: "martin" }) >>
|
15
|
+
HttpFp::Httpie.req).(empty_req)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_should_return_a_curl_command
|
data/test/http_fp/rack_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "minitest_helper"
|
2
|
+
require "rack"
|
3
|
+
require "http_fp/rack"
|
4
4
|
|
5
5
|
# https://github.com/macournoyer/thin/blob/a7d1174f47a4491a15b505407c0501cdc8d8d12c/spec/request/parser_spec.rb
|
6
6
|
# rack sample
|
@@ -9,36 +9,27 @@ class HttpFp::RackTest < MiniTest::Test
|
|
9
9
|
include HttpFp
|
10
10
|
|
11
11
|
def setup
|
12
|
-
@req = HttpFp.empty_req
|
12
|
+
@req = HttpFp.empty_req.then(&with_host.("http://localhost:3000"))
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_upcase_headers
|
16
|
-
req = @req
|
16
|
+
req = @req.then(&add_headers.("X-invisible" => "tata"))
|
17
17
|
env = Rack.to_env.(req)
|
18
|
-
assert_equal "tata",
|
18
|
+
assert_equal "tata", env["HTTP_X_INVISIBLE"]
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_basic_headers
|
22
|
-
env = empty_req
|
23
|
-
with_host.("https://localhost:3000") >>+
|
24
|
-
with_query.({"name" => "martin"}) >>+
|
25
|
-
with_path.("/users/1") >>+
|
26
|
-
Rack.to_env
|
22
|
+
env = empty_req.then(&(verb.("get") >> with_host.("https://localhost:3000") >> with_query.({ "name" => "martin" }) >> with_path.("/users/1") >> Rack.to_env))
|
27
23
|
# assert_equal "HTTP/1.1", env["SERVER_PROTOCOL"]
|
28
24
|
# assert_equal "HTTP/1.1", env["HTTP_VERSION"]
|
29
25
|
# assert_equal "/users/1", env["REQUEST_PATH"]
|
30
26
|
assert_equal "GET", env["REQUEST_METHOD"]
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
27
|
+
assert_equal "https", env["rack.url_scheme"]
|
28
|
+
assert_equal "/users/1", env["PATH_INFO"]
|
33
29
|
end
|
34
30
|
|
35
31
|
def test_host
|
36
|
-
env = empty_req
|
37
|
-
verb.("get") >>+
|
38
|
-
with_host.("https://localhost:3000") >>+
|
39
|
-
with_query.({"name" => "martin"}) >>+
|
40
|
-
with_path.("/users/1") >>+
|
41
|
-
Rack.to_env
|
32
|
+
env = empty_req.then(&(verb.("get") >> with_host.("https://localhost:3000") >> with_query.({ "name" => "martin" }) >> with_path.("/users/1") >> Rack.to_env))
|
42
33
|
# assert_equal "localhost:3000", env["HTTP_HOST"]
|
43
34
|
assert_equal "localhost", env["SERVER_NAME"]
|
44
35
|
assert_equal 3000, env["SERVER_PORT"]
|
@@ -47,15 +38,8 @@ class HttpFp::RackTest < MiniTest::Test
|
|
47
38
|
end
|
48
39
|
|
49
40
|
def test_dont_prepend_HTTP_to_content_type_and_content_length
|
50
|
-
env = empty_req
|
51
|
-
verb.("get") >>+
|
52
|
-
with_host.("https://localhost:3000") >>+
|
53
|
-
with_query.({"name" => "martin"}) >>+
|
54
|
-
with_path.("/users/1") >>+
|
55
|
-
add_headers.({"content-type" => "application/json"}) >>+
|
56
|
-
Rack.to_env
|
41
|
+
env = empty_req.then(&(verb.("get") >> with_host.("https://localhost:3000") >> with_query.({ "name" => "martin" }) >> with_path.("/users/1") >> add_headers.({ "content-type" => "application/json" }) >> Rack.to_env))
|
57
42
|
assert_equal "application/json", env["CONTENT_TYPE"]
|
58
43
|
assert_equal 0, env["CONTENT_LENGTH"]
|
59
44
|
end
|
60
45
|
end
|
61
|
-
|
data/test/http_fp_test.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "minitest_helper"
|
2
|
+
require "http_fp"
|
3
3
|
|
4
4
|
class HttpFp::HttpFpTest < Minitest::Test
|
5
5
|
include HttpFp
|
6
6
|
|
7
7
|
def test_basic_auth
|
8
|
-
req =
|
8
|
+
req = with_basic_auth.("martin").("secret").(empty_req)
|
9
9
|
authorization = req[:header]["Authorization"]
|
10
10
|
refute_nil authorization
|
11
11
|
assert_equal "Basic bWFydGluOnNlY3JldA==", authorization
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_fp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Chabot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,21 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: superators19
|
70
|
+
name: fn_reader
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
@@ -144,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
130
|
- !ruby/object:Gem::Version
|
145
131
|
version: '0'
|
146
132
|
requirements: []
|
147
|
-
|
148
|
-
rubygems_version: 2.6.10
|
133
|
+
rubygems_version: 3.0.1
|
149
134
|
signing_key:
|
150
135
|
specification_version: 4
|
151
136
|
summary: Http client that levrage the use of fp principle
|