tilia-http 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +35 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +3 -0
  7. data/CHANGELOG.sabre.md +235 -0
  8. data/CONTRIBUTING.md +25 -0
  9. data/Gemfile +18 -0
  10. data/Gemfile.lock +69 -0
  11. data/LICENSE +27 -0
  12. data/LICENSE.sabre +27 -0
  13. data/README.md +68 -0
  14. data/Rakefile +17 -0
  15. data/examples/asyncclient.rb +45 -0
  16. data/examples/basicauth.rb +39 -0
  17. data/examples/client.rb +20 -0
  18. data/examples/reverseproxy.rb +39 -0
  19. data/examples/stringify.rb +37 -0
  20. data/lib/tilia/http/auth/abstract_auth.rb +51 -0
  21. data/lib/tilia/http/auth/aws.rb +191 -0
  22. data/lib/tilia/http/auth/basic.rb +43 -0
  23. data/lib/tilia/http/auth/bearer.rb +37 -0
  24. data/lib/tilia/http/auth/digest.rb +187 -0
  25. data/lib/tilia/http/auth.rb +12 -0
  26. data/lib/tilia/http/client.rb +452 -0
  27. data/lib/tilia/http/client_exception.rb +15 -0
  28. data/lib/tilia/http/client_http_exception.rb +37 -0
  29. data/lib/tilia/http/http_exception.rb +21 -0
  30. data/lib/tilia/http/message.rb +241 -0
  31. data/lib/tilia/http/message_decorator_trait.rb +183 -0
  32. data/lib/tilia/http/message_interface.rb +154 -0
  33. data/lib/tilia/http/request.rb +235 -0
  34. data/lib/tilia/http/request_decorator.rb +160 -0
  35. data/lib/tilia/http/request_interface.rb +126 -0
  36. data/lib/tilia/http/response.rb +164 -0
  37. data/lib/tilia/http/response_decorator.rb +58 -0
  38. data/lib/tilia/http/response_interface.rb +36 -0
  39. data/lib/tilia/http/sapi.rb +165 -0
  40. data/lib/tilia/http/url_util.rb +70 -0
  41. data/lib/tilia/http/util.rb +51 -0
  42. data/lib/tilia/http/version.rb +9 -0
  43. data/lib/tilia/http.rb +416 -0
  44. data/test/http/auth/aws_test.rb +189 -0
  45. data/test/http/auth/basic_test.rb +60 -0
  46. data/test/http/auth/bearer_test.rb +47 -0
  47. data/test/http/auth/digest_test.rb +141 -0
  48. data/test/http/client_mock.rb +101 -0
  49. data/test/http/client_test.rb +331 -0
  50. data/test/http/message_decorator_test.rb +67 -0
  51. data/test/http/message_test.rb +163 -0
  52. data/test/http/request_decorator_test.rb +87 -0
  53. data/test/http/request_test.rb +132 -0
  54. data/test/http/response_decorator_test.rb +28 -0
  55. data/test/http/response_test.rb +38 -0
  56. data/test/http/sapi_mock.rb +12 -0
  57. data/test/http/sapi_test.rb +133 -0
  58. data/test/http/url_util_test.rb +155 -0
  59. data/test/http/util_test.rb +186 -0
  60. data/test/http_test.rb +102 -0
  61. data/test/test_helper.rb +6 -0
  62. data/tilia-http.gemspec +18 -0
  63. metadata +192 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: df3c33252c3cc85f15f3f9e6acea2826940586a3
4
+ data.tar.gz: 56395b01fc8257318fded5fc26f3e1850ca4c116
5
+ SHA512:
6
+ metadata.gz: df86049b2ae6d5b492addf9a2d0c49682b2696280e42bb6b7aa1e12be21531c5eb28c07f28f823d8cf8a57d28332bb1b25eb4ed9c43d789b760af6166e471831
7
+ data.tar.gz: 7e7655183e6859a16ad274fd455fc75d24e52645a83a1c8a279ecde95629d1d40709557b43ec180be46ad59976c0ee2bae23b65ac354495b8fe6a634d0910acc
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ # Gem files
2
+ /*.gem
3
+
4
+ # backup files
5
+ *~
6
+
7
+ # swap files
8
+ *.swp
9
+ *.kate-swp
10
+
11
+ # file manager files
12
+ *.directory
13
+
14
+ # coverage
15
+ /coverage
16
+
17
+ # documentation
18
+ /doc
19
+ /.yardoc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+ # Disable metrics - we stick to the sabre coding
2
+ Metrics/AbcSize:
3
+ Enabled: false
4
+
5
+ Metrics/BlockNesting:
6
+ Enabled: false
7
+
8
+ Metrics/ClassLength:
9
+ Enabled: false
10
+
11
+ Metrics/ModuleLength:
12
+ Enabled: false
13
+
14
+ Metrics/CyclomaticComplexity:
15
+ Enabled: false
16
+
17
+ Metrics/LineLength:
18
+ Enabled: false
19
+
20
+ Metrics/MethodLength:
21
+ Enabled: false
22
+
23
+ Metrics/ParameterLists:
24
+ Enabled: false
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Enabled: false
28
+
29
+ Style/OptionalArguments:
30
+ Enabled: false
31
+
32
+ # ['word', 'array'] looks better when aligned with other arrays that can't use
33
+ # %w() syntax
34
+ Style/WordArray:
35
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,4 @@
1
+ SimpleCov.start do
2
+ add_filter "/spec/"
3
+ end
4
+
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
@@ -0,0 +1,235 @@
1
+ ChangeLog
2
+ =========
3
+
4
+ 4.1.0 (2015-09-04)
5
+ ------------------
6
+
7
+ * The async client wouldn't `wait()` for new http requests being started
8
+ after the (previous) last request in the queue was resolved.
9
+ * Added `Sabre\HTTP\Auth\Bearer`, to easily extract a OAuth2 bearer token.
10
+
11
+
12
+ 4.0.0 (2015-05-20)
13
+ ------------------
14
+
15
+ * Deprecated: All static functions from `Sabre\HTTP\URLUtil` and
16
+ `Sabre\HTTP\Util` moved to a separate `functions.php`, which is also
17
+ autoloaded. The old functions are still there, but will be removed in a
18
+ future version. (#49)
19
+
20
+
21
+ 4.0.0-alpha3 (2015-05-19)
22
+ -------------------------
23
+
24
+ * Added a parser for the HTTP `Prefer` header, as defined in [RFC7240][rfc7240].
25
+ * Deprecated `Sabre\HTTP\Util::parseHTTPDate`, use `Sabre\HTTP\parseDate()`.
26
+ * Deprecated `Sabre\HTTP\Util::toHTTPDate` use `Sabre\HTTP\toDate()`.
27
+
28
+
29
+ 4.0.0-alpha2 (2015-05-18)
30
+ -------------------------
31
+
32
+ * #45: Don't send more data than what is promised in the HTTP content-length.
33
+ (@dratini0).
34
+ * #43: `getCredentials` returns null if incomplete. (@Hywan)
35
+ * #48: Now using php-cs-fixer to make our CS consistent (yay!)
36
+ * This includes fixes released in version 3.0.5.
37
+
38
+
39
+ 4.0.0-alpha1 (2015-02-25)
40
+ -------------------------
41
+
42
+ * #41: Fixing bugs related to comparing URLs in `Request::getPath()`.
43
+ * #41: This library now uses the `sabre/uri` package for uri handling.
44
+ * Added `421 Misdirected Request` from the HTTP/2.0 spec.
45
+
46
+
47
+ 3.0.5 (2015-05-11)
48
+ ------------------
49
+
50
+ * #47 #35: When re-using the client and doing any request after a `HEAD`
51
+ request, the client discards the body.
52
+
53
+
54
+ 3.0.4 (2014-12-10)
55
+ ------------------
56
+
57
+ * #38: The Authentication helpers no longer overwrite any existing
58
+ `WWW-Authenticate` headers, but instead append new headers. This ensures
59
+ that multiple authentication systems can exist in the same environment.
60
+
61
+
62
+ 3.0.3 (2014-12-03)
63
+ ------------------
64
+
65
+ * Hiding `Authorization` header value from `Request::__toString`.
66
+
67
+
68
+ 3.0.2 (2014-10-09)
69
+ ------------------
70
+
71
+ * When parsing `Accept:` headers, we're ignoring invalid parts. Before we
72
+ would throw a PHP E_NOTICE.
73
+
74
+
75
+ 3.0.1 (2014-09-29)
76
+ ------------------
77
+
78
+ * Minor change in unittests.
79
+
80
+
81
+ 3.0.0 (2014-09-23)
82
+ ------------------
83
+
84
+ * `getHeaders()` now returns header values as an array, just like psr/http.
85
+ * Added `hasHeader()`.
86
+
87
+
88
+ 2.1.0-alpha1 (2014-09-15)
89
+ -------------------------
90
+
91
+ * Changed: Copied most of the header-semantics for the PSR draft for
92
+ representing HTTP messages. [Reference here][psr-http].
93
+ * This means that `setHeaders()` does not wipe out every existing header
94
+ anymore.
95
+ * We also support multiple headers with the same name.
96
+ * Use `Request::getHeaderAsArray()` and `Response::getHeaderAsArray()` to
97
+ get a hold off multiple headers with the same name.
98
+ * If you use `getHeader()`, and there's more than 1 header with that name, we
99
+ concatenate all these with a comma.
100
+ * `addHeader()` will now preserve an existing header with that name, and add a
101
+ second header with the same name.
102
+ * The message class should be a lot faster now for looking up headers. No more
103
+ array traversal, because we maintain a tiny index.
104
+ * Added: `URLUtil::resolve()` to make resolving relative urls super easy.
105
+ * Switched to PSR-4.
106
+ * #12: Circumventing CURL's FOLLOW_LOCATION and doing it in PHP instead. This
107
+ fixes compatibility issues with people that have open_basedir turned on.
108
+ * Added: Content negotiation now correctly support mime-type parameters such as
109
+ charset.
110
+ * Changed: `Util::negotiate()` is now deprecated. Use
111
+ `Util::negotiateContentType()` instead.
112
+ * #14: The client now only follows http and https urls.
113
+
114
+
115
+ 2.0.4 (2014-07-14)
116
+ ------------------
117
+
118
+ * Changed: No longer escaping @ in urls when it's not needed.
119
+ * Fixed: #7: Client now correctly deals with responses without a body.
120
+
121
+
122
+ 2.0.3 (2014-04-17)
123
+ ------------------
124
+
125
+ * Now works on hhvm!
126
+ * Fixed: Now throwing an error when a Request object is being created with
127
+ arguments that were valid for sabre/http 1.0. Hopefully this will aid with
128
+ debugging for upgraders.
129
+
130
+
131
+ 2.0.2 (2014-02-09)
132
+ ------------------
133
+
134
+ * Fixed: Potential security problem in the client.
135
+
136
+
137
+ 2.0.1 (2014-01-09)
138
+ ------------------
139
+
140
+ * Fixed: getBodyAsString on an empty body now works.
141
+ * Fixed: Version string
142
+
143
+
144
+ 2.0.0 (2014-01-08)
145
+ ------------------
146
+
147
+ * Removed: Request::createFromPHPRequest. This is now handled by
148
+ Sapi::getRequest.
149
+
150
+
151
+ 2.0.0alpha6 (2014-01-03)
152
+ ------------------------
153
+
154
+ * Added: Asynchronous HTTP client. See examples/asyncclient.php.
155
+ * Fixed: Issue #4: Don't escape colon (:) when it's not needed.
156
+ * Fixed: Fixed a bug in the content negotation script.
157
+ * Fixed: Fallback for when CURLOPT_POSTREDIR is not defined (mainly for hhvm).
158
+ * Added: The Request and Response object now have a `__toString()` method that
159
+ serializes the objects into a standard HTTP message. This is mainly for
160
+ debugging purposes.
161
+ * Changed: Added Response::getStatusText(). This method returns the
162
+ human-readable HTTP status message. This part has been removed from
163
+ Response::getStatus(), which now always returns just the status code as an
164
+ int.
165
+ * Changed: Response::send() is now Sapi::sendResponse($response).
166
+ * Changed: Request::createFromPHPRequest is now Sapi::getRequest().
167
+ * Changed: Message::getBodyAsStream and Message::getBodyAsString were added. The
168
+ existing Message::getBody changed it's behavior, so be careful.
169
+
170
+
171
+ 2.0.0alpha5 (2013-11-07)
172
+ ------------------------
173
+
174
+ * Added: HTTP Status 451 Unavailable For Legal Reasons. Fight government
175
+ censorship!
176
+ * Added: Ability to catch and retry http requests in the client when a curl
177
+ error occurs.
178
+ * Changed: Request::getPath does not return the query part of the url, so
179
+ everything after the ? is stripped.
180
+ * Added: a reverse proxy example.
181
+
182
+
183
+ 2.0.0alpha4 (2013-08-07)
184
+ ------------------------
185
+
186
+ * Fixed: Doing a GET request with the client uses the last used HTTP method
187
+ instead.
188
+ * Added: HttpException
189
+ * Added: The Client class can now automatically emit exceptions when HTTP errors
190
+ occurred.
191
+
192
+
193
+ 2.0.0alpha3 (2013-07-24)
194
+ ------------------------
195
+
196
+ * Changed: Now depends on sabre/event package.
197
+ * Changed: setHeaders() now overwrites any existing http headers.
198
+ * Added: getQueryParameters to RequestInterface.
199
+ * Added: Util::negotiate.
200
+ * Added: RequestDecorator, ResponseDecorator.
201
+ * Added: A very simple HTTP client.
202
+ * Added: addHeaders() to append a list of new headers.
203
+ * Fixed: Not erroring on unknown HTTP status codes.
204
+ * Fixed: Throwing exceptions on invalid HTTP status codes (not 3 digits).
205
+ * Fixed: Much better README.md
206
+ * Changed: getBody() now uses a bitfield to specify what type to return.
207
+
208
+
209
+ 2.0.0alpha2 (2013-07-02)
210
+ ------------------------
211
+
212
+ * Added: Digest & AWS Authentication.
213
+ * Added: Message::getHttpVersion and Message::setHttpVersion.
214
+ * Added: Request::setRawServerArray, getRawServerValue.
215
+ * Added: Request::createFromPHPRequest
216
+ * Added: Response::send
217
+ * Added: Request::getQueryParameters
218
+ * Added: Utility for dealing with HTTP dates.
219
+ * Added: Request::setPostData and Request::getPostData.
220
+ * Added: Request::setAbsoluteUrl and Request::getAbsoluteUrl.
221
+ * Added: URLUtil, methods for calculation relative and base urls.
222
+ * Removed: Response::sendBody
223
+
224
+
225
+ 2.0.0alpha1 (2012-10-07)
226
+ ------------------------
227
+
228
+ * Fixed: Lots of small naming improvements
229
+ * Added: Introduction of Message, MessageInterface, Response, ResponseInterface.
230
+
231
+ Before 2.0.0, this package was built-into SabreDAV, where it first appeared in
232
+ January 2009.
233
+
234
+ [psr-http]: https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md
235
+ [rfc-7240]: http://tools.ietf.org/html/rfc7240
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.
4
+ [code-of-conduct]: http://todogroup.org/opencodeofconduct/#tilia-http/tilia@jakobsack.de
5
+
6
+ This library is a port of [sabre/http](http://github.com/fruux/sabre-http). The ruby code should match the php code as good as possible. For more information refer to the [coding guidelines](https://tilia.github.io/coding_guidelines).
7
+
8
+ If you are having an issue [search the open issues](https://github.com/tilia/tilia-http/issues) or create an issue and we'll help point you in the right direction.
9
+
10
+ ## Submitting a Pull Request
11
+
12
+ * Fork the project on Github
13
+ * Install development dependencies (`bundle install`)
14
+ * Create a topic branch for your changes
15
+ * Ensure that you provide *documentation* and *test coverage* for your changes (patches won't be accepted without)
16
+ * Ensure that all tests pass (`bundle exec rake`)
17
+ * Create a [pull request](https://github.com/tilia/tilia-http/pulls) on Github (these are also a great place to start a conversation around a patch as early as possible)
18
+
19
+ ## Testing
20
+
21
+ To run the tests:
22
+
23
+ $ rake
24
+
25
+ If nothing complains, congratulations!
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Internal dependencies
4
+ gem 'tilia-event', '~> 2.0'
5
+ gem 'tilia-uri', '~> 1.0'
6
+
7
+ # External dependencies
8
+ gem 'activesupport', '~> 4.2'
9
+ gem 'typhoeus', '~> 0.8'
10
+ gem 'rchardet', '~>1.6'
11
+ gem 'rack', '~> 1.6'
12
+
13
+ # Testing
14
+ gem 'rake'
15
+ gem 'minitest', '~> 5.8'
16
+ gem 'simplecov', '~> 0.10'
17
+ gem 'rubocop', '~> 0.34'
18
+ gem 'yard', '~> 0.8'
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.5)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ docile (1.1.5)
14
+ ethon (0.8.0)
15
+ ffi (>= 1.3.0)
16
+ ffi (1.9.10)
17
+ i18n (0.7.0)
18
+ json (1.8.3)
19
+ minitest (5.8.3)
20
+ parser (2.2.3.0)
21
+ ast (>= 1.1, < 3.0)
22
+ powerpack (0.1.1)
23
+ rack (1.6.4)
24
+ rainbow (2.0.0)
25
+ rake (10.4.2)
26
+ rchardet (1.6.1)
27
+ rubocop (0.35.1)
28
+ astrolabe (~> 1.3)
29
+ parser (>= 2.2.3.0, < 3.0)
30
+ powerpack (~> 0.1)
31
+ rainbow (>= 1.99.1, < 3.0)
32
+ ruby-progressbar (~> 1.7)
33
+ tins (<= 1.6.0)
34
+ ruby-progressbar (1.7.5)
35
+ simplecov (0.11.1)
36
+ docile (~> 1.1.0)
37
+ json (~> 1.8)
38
+ simplecov-html (~> 0.10.0)
39
+ simplecov-html (0.10.0)
40
+ thread_safe (0.3.5)
41
+ tilia-event (2.0.2)
42
+ activesupport (~> 4.2)
43
+ tilia-uri (1.0.1)
44
+ activesupport (~> 4.2)
45
+ tins (1.6.0)
46
+ typhoeus (0.8.0)
47
+ ethon (>= 0.8.0)
48
+ tzinfo (1.2.2)
49
+ thread_safe (~> 0.1)
50
+ yard (0.8.7.6)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ activesupport (~> 4.2)
57
+ minitest (~> 5.8)
58
+ rack (~> 1.6)
59
+ rake
60
+ rchardet (~> 1.6)
61
+ rubocop (~> 0.34)
62
+ simplecov (~> 0.10)
63
+ tilia-event (~> 2.0)
64
+ tilia-uri (~> 1.0)
65
+ typhoeus (~> 0.8)
66
+ yard (~> 0.8)
67
+
68
+ BUNDLED WITH
69
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (C) 2015 Jakob Sack (tilia@jakobsack.de)
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ * Neither the name Tilia nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software
15
+ without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ POSSIBILITY OF SUCH DAMAGE.
data/LICENSE.sabre ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/)
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ * Neither the name Sabre nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software
15
+ without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ tilia/http
2
+ =========
3
+
4
+ [![Build Status](https://travis-ci.org/tilia/tilia-http.svg?branch=master)](https://travis-ci.org/tilia/tilia-http)
5
+
6
+ **tilia/http is a port of [sabre/http](https://github.com/fruux/sabre-http)**
7
+
8
+ The sabre/http library provides a toolkit to make working with the HTTP protocol easier.
9
+
10
+ Most PHP scripts run within a HTTP request but accessing information about the
11
+ HTTP request is cumbersome at least.
12
+
13
+ There's bad practices, inconsistencies and confusion. This library is
14
+ effectively a wrapper around the following PHP constructs:
15
+
16
+ For Input:
17
+
18
+ * `$_GET`,
19
+ * `$_POST`,
20
+ * `$_SERVER`,
21
+ * `php://input` or `$HTTP_RAW_POST_DATA`.
22
+
23
+ For output:
24
+
25
+ * `php://output` or `echo`,
26
+ * `header()`.
27
+
28
+ What this library provides, is a `Request` object, and a `Response` object.
29
+
30
+ The objects are extendable and easily mockable.
31
+
32
+
33
+ Installation
34
+ ------------
35
+
36
+ Simply add tilia-http to your Gemfile and bundle it up:
37
+
38
+ ```ruby
39
+ gem 'tilia-http', '~> 4.1'
40
+ ```
41
+
42
+
43
+ Changes to sabre/http
44
+ ---------------------
45
+
46
+ ```php
47
+ Sabre\HTTP\Message#setHeader($name, $value)
48
+ Sabre\HTTP\Message#setHeader(array $headers)
49
+ ```
50
+
51
+ are replaced by
52
+
53
+ ```ruby
54
+ Tilia::Http::Message#update_header(name, value)
55
+ Tilia::Http::Message#update_headers(headers)
56
+ ```
57
+
58
+
59
+ Contributing
60
+ ------------
61
+
62
+ See [Contributing](CONTRIBUTING.md)
63
+
64
+
65
+ License
66
+ -------
67
+
68
+ tilia-http is licensed under the terms of the [three-clause BSD-license](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+ require 'yard'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = Dir.glob('test/**/*_test.rb')
8
+ t.libs << 'test'
9
+ end
10
+ RuboCop::RakeTask.new do |t|
11
+ t.options = ['--format', 'html', '--out', 'coverage/rubocop.html']
12
+ end
13
+ YARD::Rake::YardocTask.new do |t|
14
+ t.files = ['lib/**/*.rb', '-', 'README.md']
15
+ end
16
+
17
+ task(default: :test)
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # This example demonstrates the ability for clients to work asynchronously.
3
+ #
4
+ # By default up to 10 requests will be executed in paralel. HTTP connections
5
+ # are re-used and DNS is cached, all thanks to the power of curl.
6
+ #
7
+ # @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
8
+ # @author Evert Pot (http://evertpot.com/)
9
+ # @license http://sabre.io/license/ Modified BSD License
10
+
11
+ # Expected to be called "bundle exec examples/asyncclient.rb"
12
+ require './lib/tilia/http'
13
+
14
+ # This is the request we're repeating a 1000 times.
15
+ request = Tilia::Http::Request.new('GET', 'http://localhost/')
16
+ client = Tilia::Http::Client.new
17
+
18
+ 1000.times do |i|
19
+ puts "#{i}\tsending"
20
+
21
+ # This is the 'success' callback
22
+ success = lambda do |response|
23
+ puts "#{i}\t#{response.status}"
24
+ end
25
+
26
+ # This is the 'error' callback. It is called for general connection
27
+ # problems (such as not being able to connect to a host, dns errors,
28
+ # etc.) and also cases where a response was returned, but it had a
29
+ # status code of 400 or higher.
30
+ exception = lambda do |error|
31
+ if error['status'] == Tilia::Http::Client::STATUS_CURLERROR
32
+ # Curl errors
33
+ puts "#{i}\tcurl error: #{error['curl_errmsg']}"
34
+ else
35
+ # HTTP errors
36
+ puts "#{i}\t#{error['response'].status}"
37
+ end
38
+ end
39
+
40
+ client.send_async(request, success, exception)
41
+ end
42
+
43
+ # After everything is done, we call 'wait'. This causes the client to wait for
44
+ # all outstanding http requests to complete.
45
+ client.wait
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ # This example does not work because of rack ...
3
+ # This example shows how to do Basic authentication.
4
+ # *
5
+ # @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
6
+ # @author Evert Pot (http://evertpot.com/)
7
+ # @license http://sabre.io/license/ Modified BSD License
8
+
9
+ # Expected to be called "bundle exec examples/basicauth.rb"
10
+ require './lib/tilia_http'
11
+ require 'rack'
12
+
13
+ app = proc do |env|
14
+ user_list = {
15
+ 'user1' => 'password',
16
+ 'user2' => 'password'
17
+ }
18
+
19
+ sapi = Tilia::Http::Sapi.new(env)
20
+ request = sapi.request
21
+ response = Tilia::Http::Response.new
22
+
23
+ basic_auth = Tilia::Http::Auth::Basic.new('Locked down area', request, response)
24
+ if !(user_pass = basic_auth.credentials)
25
+ # No username or password given
26
+ basic_auth.require_login
27
+ elsif !user_list.key?(user_pass[0]) || user_list[user_pass[0]] != user_pass[1]
28
+ # Username or password are incorrect
29
+ basic_auth.require_login
30
+ else
31
+ # Success !
32
+ response.body = 'You are logged in!'
33
+ end
34
+
35
+ # Sending the response
36
+ sapi.send_response(response)
37
+ end
38
+
39
+ Rack::Handler::WEBrick.run app
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # This example shows how to make a HTTP request with the Request and Response
3
+ # objects.
4
+ #
5
+ # @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
6
+ # @author Evert Pot (http://evertpot.com/)
7
+ # @license http://sabre.io/license/ Modified BSD License
8
+
9
+ # Expected to be called "bundle exec examples/client.rb"
10
+ require './lib/tilia_http'
11
+
12
+ # Constructing the request.
13
+ request = Tilia::Http::Request.new('GET', 'http://www.jakobsack.de/')
14
+
15
+ client = Tilia::Http::Client.new
16
+ # client.add_curl_setting(proxy: 'localhost:8888')
17
+ response = client.send(request)
18
+
19
+ puts 'Response:'
20
+ puts response.to_s