Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
wheeOs
2022-07-11 17:33:14 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2022-07-11 17:33:14 +0200
Commit
b5c3f96e8f5636a20565cee4193dfa0de2fefda0
b5c3f96e
1 parent
6ab6adb7
Update http.dart
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
lib/get_connect/http/src/http.dart
lib/get_connect/http/src/http.dart
View file @
b5c3f96
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'../src/certificates/certificates.dart'
;
import
'../src/exceptions/exceptions.dart'
;
...
...
@@ -17,6 +18,8 @@ typedef Decoder<T> = T Function(dynamic data);
typedef
Progress
=
Function
(
double
percent
);
typedef
ResponseInterceptor
<
T
>
=
Future
<
Response
<
T
>?>
Function
(
Request
<
T
>
request
,
Type
targetType
,
HttpClientResponse
response
);
class
GetHttpClient
{
String
userAgent
;
String
?
baseUrl
;
...
...
@@ -31,6 +34,7 @@ class GetHttpClient {
bool
sendContentLength
;
Decoder
?
defaultDecoder
;
ResponseInterceptor
?
defaultResponseInterceptor
;
Duration
timeout
;
...
...
@@ -101,6 +105,7 @@ class GetHttpClient {
String
method
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
Progress
?
uploadProgress
,
)
async
{
List
<
int
>?
bodyBytes
;
...
...
@@ -113,7 +118,7 @@ class GetHttpClient {
if
(
body
is
FormData
)
{
bodyBytes
=
await
body
.
toBytes
();
_setContentLenght
(
headers
,
bodyBytes
.
length
);
headers
[
'content-length'
]
=
bodyBytes
.
length
.
toString
(
);
headers
[
'content-type'
]
=
'multipart/form-data; boundary=
${body.boundary}
'
;
}
else
if
(
contentType
!=
null
&&
...
...
@@ -161,6 +166,7 @@ class GetHttpClient {
followRedirects:
followRedirects
,
maxRedirects:
maxRedirects
,
decoder:
decoder
,
responseInterceptor:
responseInterceptor
);
}
...
...
@@ -269,6 +275,7 @@ class GetHttpClient {
String
?
contentType
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
)
{
final
headers
=
<
String
,
String
>{};
_setSimpleHeaders
(
headers
,
contentType
);
...
...
@@ -279,12 +286,21 @@ class GetHttpClient {
url:
uri
,
headers:
headers
,
decoder:
decoder
??
(
defaultDecoder
as
Decoder
<
T
>?),
responseInterceptor:
_responseInterceptor
(
responseInterceptor
),
contentLength:
0
,
followRedirects:
followRedirects
,
maxRedirects:
maxRedirects
,
));
}
ResponseInterceptor
<
T
>?
_responseInterceptor
<
T
>(
ResponseInterceptor
<
T
>?
actual
)
{
if
(
actual
!=
null
)
return
actual
;
final
defaultInterceptor
=
defaultResponseInterceptor
;
return
defaultInterceptor
!=
null
?
(
request
,
targetType
,
response
)
async
=>
await
defaultInterceptor
(
request
,
targetType
,
response
)
as
Response
<
T
>?
:
null
;
}
Future
<
Request
<
T
>>
_request
<
T
>(
String
?
url
,
String
method
,
{
...
...
@@ -292,6 +308,7 @@ class GetHttpClient {
required
dynamic
body
,
required
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
required
Progress
?
uploadProgress
,
})
{
return
_requestWithBody
<
T
>(
...
...
@@ -301,6 +318,7 @@ class GetHttpClient {
method
,
query
,
decoder
??
(
defaultDecoder
as
Decoder
<
T
>?),
_responseInterceptor
(
responseInterceptor
),
uploadProgress
,
);
}
...
...
@@ -310,6 +328,7 @@ class GetHttpClient {
String
?
contentType
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
)
{
final
headers
=
<
String
,
String
>{};
_setSimpleHeaders
(
headers
,
contentType
);
...
...
@@ -320,6 +339,7 @@ class GetHttpClient {
url:
uri
,
headers:
headers
,
decoder:
decoder
??
(
defaultDecoder
as
Decoder
<
T
>?),
responseInterceptor:
_responseInterceptor
(
responseInterceptor
),
);
}
...
...
@@ -330,6 +350,7 @@ class GetHttpClient {
Map
<
String
,
String
>?
headers
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
Progress
?
uploadProgress
,
// List<MultipartFile> files,
})
async
{
...
...
@@ -342,6 +363,7 @@ class GetHttpClient {
body:
body
,
query:
query
,
decoder:
decoder
,
responseInterceptor:
responseInterceptor
,
uploadProgress:
uploadProgress
,
),
headers:
headers
,
...
...
@@ -364,6 +386,7 @@ class GetHttpClient {
Map
<
String
,
String
>?
headers
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
Progress
?
uploadProgress
,
// List<MultipartFile> files,
})
async
{
...
...
@@ -376,6 +399,7 @@ class GetHttpClient {
body:
body
,
query:
query
,
decoder:
decoder
,
responseInterceptor:
responseInterceptor
,
uploadProgress:
uploadProgress
,
),
headers:
headers
,
...
...
@@ -399,6 +423,7 @@ class GetHttpClient {
Map
<
String
,
String
>?
headers
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
Progress
?
uploadProgress
,
})
async
{
try
{
...
...
@@ -410,6 +435,7 @@ class GetHttpClient {
query:
query
,
body:
body
,
decoder:
decoder
,
responseInterceptor:
responseInterceptor
,
uploadProgress:
uploadProgress
,
),
headers:
headers
,
...
...
@@ -432,6 +458,7 @@ class GetHttpClient {
Map
<
String
,
String
>?
headers
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
Progress
?
uploadProgress
,
})
async
{
try
{
...
...
@@ -443,6 +470,7 @@ class GetHttpClient {
query:
query
,
body:
body
,
decoder:
decoder
,
responseInterceptor:
responseInterceptor
,
uploadProgress:
uploadProgress
,
),
headers:
headers
,
...
...
@@ -464,10 +492,11 @@ class GetHttpClient {
String
?
contentType
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
,
})
async
{
try
{
var
response
=
await
_performRequest
<
T
>(
()
=>
_get
<
T
>(
url
,
contentType
,
query
,
decoder
),
()
=>
_get
<
T
>(
url
,
contentType
,
query
,
decoder
,
responseInterceptor
),
headers:
headers
,
);
return
response
;
...
...
@@ -548,10 +577,11 @@ class GetHttpClient {
String
?
contentType
,
Map
<
String
,
dynamic
>?
query
,
Decoder
<
T
>?
decoder
,
ResponseInterceptor
<
T
>?
responseInterceptor
})
async
{
try
{
var
response
=
await
_performRequest
<
T
>(
()
async
=>
_delete
<
T
>(
url
,
contentType
,
query
,
decoder
),
()
async
=>
_delete
<
T
>(
url
,
contentType
,
query
,
decoder
,
responseInterceptor
),
headers:
headers
,
);
return
response
;
...
...
Please
register
or
login
to post a comment