Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix Ruby SDK
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Olofsson
Matrix Ruby SDK
Commits
84be3dd9
Verified
Commit
84be3dd9
authored
4 years ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
api: no more reuse of HTTP request objects
Hopefully improves compatibility with JRuby
parent
3be8f960
No related branches found
No related tags found
No related merge requests found
Pipeline
#21625
failed
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/matrix_sdk/api.rb
+27
-19
27 additions, 19 deletions
lib/matrix_sdk/api.rb
with
27 additions
and
19 deletions
lib/matrix_sdk/api.rb
+
27
−
19
View file @
84be3dd9
...
...
@@ -268,23 +268,6 @@ module MatrixSdk
u
.
query
=
[
u
.
query
,
URI
.
encode_www_form
(
options
.
fetch
(
:query
))].
flatten
.
compact
.
join
(
'&'
)
if
options
[
:query
]
u
.
query
=
nil
if
u
.
query
.
nil?
||
u
.
query
.
empty?
end
request
=
Net
::
HTTP
.
const_get
(
method
.
to_s
.
capitalize
.
to_sym
).
new
url
.
request_uri
request
.
body
=
options
[
:body
]
if
options
.
key?
:body
request
.
body
=
request
.
body
.
to_json
if
options
.
key?
(
:body
)
&&
!
request
.
body
.
is_a?
(
String
)
request
.
body_stream
=
options
[
:body_stream
]
if
options
.
key?
:body_stream
global_headers
.
each
{
|
h
,
v
|
request
[
h
]
=
v
}
if
request
.
body
||
request
.
body_stream
request
.
content_type
=
'application/json'
request
.
content_length
=
(
request
.
body
||
request
.
body_stream
).
size
end
request
[
'authorization'
]
=
"Bearer
#{
access_token
}
"
if
access_token
&&
!
options
.
fetch
(
:skip_auth
,
false
)
if
options
.
key?
:headers
options
[
:headers
].
each
do
|
h
,
v
|
request
[
h
.
to_s
.
downcase
]
=
v
end
end
failures
=
0
loop
do
...
...
@@ -292,10 +275,11 @@ module MatrixSdk
req_id
=
(
'A'
..
'Z'
).
to_a
.
sample
(
4
).
join
print_http
(
request
,
id:
req_id
)
req_obj
=
construct_request
(
url:
url
,
method:
method
,
**
options
)
print_http
(
req_obj
,
id:
req_id
)
begin
dur_start
=
Time
.
now
response
=
http
.
request
req
uest
response
=
http
.
request
req
_obj
dur_end
=
Time
.
now
duration
=
dur_end
-
dur_start
rescue
EOFError
...
...
@@ -344,6 +328,30 @@ module MatrixSdk
private
def
construct_request
(
method
:,
url
:,
**
options
)
request
=
Net
::
HTTP
.
const_get
(
method
.
to_s
.
capitalize
.
to_sym
).
new
url
.
request_uri
# FIXME: Handle bodies better, avoid duplicating work
request
.
body
=
options
[
:body
]
if
options
.
key?
:body
request
.
body
=
request
.
body
.
to_json
if
options
.
key?
(
:body
)
&&
!
request
.
body
.
is_a?
(
String
)
request
.
body_stream
=
options
[
:body_stream
]
if
options
.
key?
:body_stream
global_headers
.
each
{
|
h
,
v
|
request
[
h
]
=
v
}
if
request
.
body
||
request
.
body_stream
request
.
content_type
=
'application/json'
request
.
content_length
=
(
request
.
body
||
request
.
body_stream
).
size
end
request
[
'authorization'
]
=
"Bearer
#{
access_token
}
"
if
access_token
&&
!
options
.
fetch
(
:skip_auth
,
false
)
if
options
.
key?
:headers
options
[
:headers
].
each
do
|
h
,
v
|
request
[
h
.
to_s
.
downcase
]
=
v
end
end
request
end
def
print_http
(
http
,
body:
true
,
duration:
nil
,
id:
nil
)
return
unless
logger
.
debug?
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment