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
kevin.zhang
2021-05-18 16:01:50 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd5aaee17514f74a9b23c54426d52dc832c4bc24
dd5aaee1
1 parent
405c8ba6
fix: 1. use returned instance for modifyResponse as well; 2. remove mandatory copyWith parameters.
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
18 deletions
lib/get_connect/http/src/http.dart
lib/get_connect/http/src/interceptors/get_modifiers.dart
lib/get_connect/http/src/request/request.dart
lib/get_connect/http/src/http.dart
View file @
dd5aaee
...
...
@@ -196,9 +196,10 @@ class GetHttpClient {
var
response
=
await
_httpClient
.
send
<
T
>(
newRequest
);
await
_modifier
.
modifyResponse
(
newRequest
,
response
);
final
newResponse
=
await
_modifier
.
modifyResponse
<
T
>(
newRequest
,
response
);
if
(
HttpStatus
.
unauthorized
==
r
esponse
.
statusCode
&&
if
(
HttpStatus
.
unauthorized
==
newR
esponse
.
statusCode
&&
_modifier
.
authenticator
!=
null
&&
requestNumber
<=
maxAuthRetries
)
{
return
_performRequest
<
T
>(
...
...
@@ -207,23 +208,23 @@ class GetHttpClient {
requestNumber:
requestNumber
+
1
,
headers:
newRequest
.
headers
,
);
}
else
if
(
HttpStatus
.
unauthorized
==
r
esponse
.
statusCode
)
{
}
else
if
(
HttpStatus
.
unauthorized
==
newR
esponse
.
statusCode
)
{
if
(!
errorSafety
)
{
throw
UnauthorizedException
();
}
else
{
return
Response
<
T
>(
request:
newRequest
,
headers:
response
.
headers
,
statusCode:
response
.
statusCode
,
body:
response
.
body
,
bodyBytes:
response
.
bodyBytes
,
bodyString:
response
.
bodyString
,
statusText:
response
.
statusText
,
headers:
newResponse
.
headers
,
statusCode:
newResponse
.
statusCode
,
body:
newResponse
.
body
,
bodyBytes:
newResponse
.
bodyBytes
,
bodyString:
newResponse
.
bodyString
,
statusText:
newResponse
.
statusText
,
);
}
}
return
r
esponse
;
return
newR
esponse
;
}
on
Exception
catch
(
err
)
{
if
(!
errorSafety
)
{
throw
GetHttpException
(
err
.
toString
());
...
...
lib/get_connect/http/src/interceptors/get_modifiers.dart
View file @
dd5aaee
...
...
@@ -42,11 +42,15 @@ class GetModifier<T> {
return
newRequest
;
}
Future
<
void
>
modifyResponse
(
Request
request
,
Response
response
)
async
{
Future
<
Response
<
T
>>
modifyResponse
<
T
>(
Request
<
T
>
request
,
Response
<
T
>
response
)
async
{
var
newResponse
=
response
;
if
(
_responseModifiers
.
isNotEmpty
)
{
for
(
var
interceptor
in
_responseModifiers
)
{
await
interceptor
(
request
,
response
)
;
newResponse
=
await
interceptor
(
request
,
response
)
as
Response
<
T
>
;
}
}
return
newResponse
;
}
}
...
...
lib/get_connect/http/src/request/request.dart
View file @
dd5aaee
...
...
@@ -76,9 +76,9 @@ class Request<T> {
}
Request
copyWith
({
required
Uri
url
,
required
String
method
,
required
Map
<
String
,
String
>
headers
,
Uri
?
url
,
String
?
method
,
Map
<
String
,
String
>?
headers
,
Stream
<
List
<
int
>>?
bodyBytes
,
bool
followRedirects
=
true
,
int
maxRedirects
=
4
,
...
...
@@ -91,10 +91,10 @@ class Request<T> {
assert
(
maxRedirects
>
0
);
}
return
Request
.
_
(
url:
url
,
method:
method
,
url:
url
??
this
.
url
,
method:
method
??
this
.
method
,
bodyBytes:
bodyBytes
??=
BodyBytesStream
.
fromBytes
(
const
[]),
headers:
Map
.
from
(
headers
),
headers:
headers
==
null
?
this
.
headers
:
Map
.
from
(
headers
),
followRedirects:
followRedirects
,
maxRedirects:
maxRedirects
,
contentLength:
contentLength
,
...
...
Please
register
or
login
to post a comment