Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexander Strizhakov
pleroma
Commits
5b837592
Commit
5b837592
authored
Sep 12, 2019
by
Alexander Strizhakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reverse proxy for mint adapter
parent
c20e64c4
Pipeline
#17035
passed with stages
in 4 minutes and 35 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
lib/pleroma/reverse_proxy/client/tesla.ex
lib/pleroma/reverse_proxy/client/tesla.ex
+32
-9
No files found.
lib/pleroma/reverse_proxy/client/tesla.ex
View file @
5b837592
...
...
@@ -5,7 +5,7 @@
defmodule
Pleroma
.
ReverseProxy
.
Client
.
Tesla
do
@behaviour
Pleroma
.
ReverseProxy
.
Client
@adapters
[
Tesla
.
Adapter
.
Gun
]
@adapters
[
Tesla
.
Adapter
.
Gun
,
Tesla
.
Adapter
.
Mint
]
def
request
(
method
,
url
,
headers
,
body
,
opts
\\
[])
do
opts
=
Keyword
.
put
(
opts
,
:body_as
,
:chunks
)
...
...
@@ -28,6 +28,24 @@ def request(method, url, headers, body, opts \\ []) do
def
stream_body
(%{
fin:
true
}),
do
:
:done
def
stream_body
(%{
body:
body
}
=
client
)
do
case
body
do
{
:fin
,
response
}
->
{
:ok
,
response
,
Map
.
put
(
client
,
:fin
,
true
)}
{
:nofin
,
response
}
->
client
=
Map
.
delete
(
client
,
:body
)
case
response
do
nil
->
stream_body
(
client
)
_binary
->
{
:ok
,
response
,
client
}
end
end
end
def
stream_body
(
client
)
do
case
read_chunk!
(
client
)
do
{
:fin
,
body
}
->
{
:ok
,
body
,
Map
.
put
(
client
,
:fin
,
true
)}
...
...
@@ -37,22 +55,27 @@ def stream_body(client) do
end
defp
read_chunk!
(%{
pid:
pid
,
stream:
stream
,
opts:
opts
})
do
adapter
=
Application
.
get_env
(
:tesla
,
:adapter
)
unless
adapter
in
@adapters
do
raise
"
#{
adapter
}
doesn't support reading body in chunks"
end
adapter
=
check_adapter
()
adapter
.
read_chunk
(
pid
,
stream
,
opts
)
end
defp
read_chunk!
(%{
conn:
conn
,
opts:
opts
})
do
adapter
=
check_adapter
()
adapter
.
read_chunk
(
conn
,
opts
)
end
def
close
(
pid
)
do
adapter
=
check_adapter
()
adapter
.
close
(
pid
)
end
defp
check_adapter
do
adapter
=
Application
.
get_env
(
:tesla
,
:adapter
)
unless
adapter
in
@adapters
do
raise
"
#{
adapter
}
doesn't support
closing connection
"
raise
"
#{
adapter
}
doesn't support
reading body in chunks
"
end
adapter
.
close
(
pid
)
adapter
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment