Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PolycentricAndroid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoStreaming
PolycentricAndroid
Commits
c91b426c
Commit
c91b426c
authored
4 months ago
by
Aidan
Browse files
Options
Downloads
Patches
Plain Diff
Add HTTP cache to API methods
parent
f7d58c6c
No related branches found
No related tags found
1 merge request
!10
Add HTTP cache to API methods and add max timeout
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/futo/polycentric/core/ApiMethods.kt
+18
-1
18 additions, 1 deletion
app/src/main/java/com/futo/polycentric/core/ApiMethods.kt
with
18 additions
and
1 deletion
app/src/main/java/com/futo/polycentric/core/ApiMethods.kt
+
18
−
1
View file @
c91b426c
...
...
@@ -16,17 +16,34 @@ import userpackage.Protocol
import
java.nio.ByteBuffer
import
kotlin.coroutines.resume
import
kotlin.coroutines.resumeWithException
import
okhttp3.Cache
import
java.io.File
import
java.util.concurrent.TimeUnit
class
ApiMethods
{
companion
object
{
var
UserAgent
=
"Grayjay Android"
;
private
const
val
TAG
=
"ApiMethods"
private
val
client
=
OkHttpClient
()
private
var
client
:
OkHttpClient
=
OkHttpClient
.
Builder
()
.
connectTimeout
(
3
,
TimeUnit
.
SECONDS
)
.
build
()
fun
initCache
(
cacheDir
:
File
)
{
client
=
OkHttpClient
.
Builder
()
.
connectTimeout
(
3
,
TimeUnit
.
SECONDS
)
.
cache
(
Cache
(
directory
=
File
(
cacheDir
,
"http_cache"
),
maxSize
=
25L
*
1024L
*
1024L
// 25 MiB
))
.
build
()
}
private
val
MEDIA_TYPE_OCTET_STREAM
=
"application/octet-stream"
.
toMediaType
()
fun
getRequestBuilder
(
url
:
String
):
Request
.
Builder
=
Request
.
Builder
().
url
(
url
).
header
(
"x-polycentric-user-agent"
,
UserAgent
)
suspend
fun
postEvents
(
server
:
String
,
events
:
Protocol
.
Events
):
Unit
=
withContext
(
Dispatchers
.
IO
)
{
val
body
=
events
.
toByteArray
().
toRequestBody
(
MEDIA_TYPE_OCTET_STREAM
)
val
request
=
getRequestBuilder
(
"$server/events"
).
post
(
body
).
build
()
...
...
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