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
Jonatas
2020-12-02 15:25:12 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
20357e47dfe23352959fbaf05a6c98166456c88b
20357e47
1 parent
b1af5977
separate jsonDecode from default decode
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
48 deletions
lib/get_connect/http/src/http.dart
lib/get_connect/http/src/http_impl/body_decoder.dart
lib/get_connect/http/src/http_impl/http_request_html.dart
lib/get_connect/http/src/http_impl/http_request_io.dart
lib/get_connect/http/src/http.dart
View file @
20357e4
...
...
@@ -104,6 +104,9 @@ class GetHttpClient {
'multipart/form-data; boundary=
${body.boundary}
'
;
}
else
if
(
body
is
Map
||
body
is
List
)
{
var
jsonString
=
json
.
encode
(
body
);
bodyBytes
=
utf8
.
encode
(
jsonString
);
headers
[
'content-length'
]
=
bodyBytes
.
length
.
toString
();
headers
[
'content-type'
]
=
contentType
??
defaultContentType
;
//TODO check this implementation
if
(
contentType
!=
null
)
{
...
...
@@ -112,9 +115,6 @@ class GetHttpClient {
jsonString
=
'
$paramName
=
${Uri.encodeQueryComponent(jsonString)}
'
;
}
}
bodyBytes
=
utf8
.
encode
(
jsonString
);
headers
[
'content-length'
]
=
bodyBytes
.
length
.
toString
();
}
else
if
(
body
==
null
)
{
headers
[
'content-type'
]
=
contentType
??
defaultContentType
;
headers
[
'content-length'
]
=
'0'
;
...
...
lib/get_connect/http/src/http_impl/body_decoder.dart
0 → 100644
View file @
20357e4
import
'dart:convert'
;
import
'../../../../get_core/get_core.dart'
;
import
'../request/request.dart'
;
T
bodyDecoded
<
T
>(
Request
<
T
>
request
,
String
stringBody
)
{
T
body
;
var
bodyToDecode
;
try
{
bodyToDecode
=
jsonDecode
(
stringBody
);
}
on
FormatException
catch
(
_
)
{
Get
.
log
(
'Cannot decode body in json'
);
bodyToDecode
=
stringBody
;
}
try
{
if
(
request
.
decoder
==
null
)
{
body
=
bodyToDecode
as
T
;
}
else
{
body
=
request
.
decoder
(
bodyToDecode
);
}
}
on
Exception
catch
(
_
)
{
body
=
stringBody
as
T
;
}
return
body
;
}
...
...
lib/get_connect/http/src/http_impl/http_request_html.dart
View file @
20357e4
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:html'
as
html
;
import
'dart:typed_data'
;
import
'../certificates/certificates.dart'
;
import
'../exceptions/exceptions.dart'
;
import
'../request/request.dart'
;
import
'../response/response.dart'
;
import
'body_decoder.dart'
;
import
'request_base.dart'
;
/// A `dart:html` implementation of `HttpRequestBase`.
...
...
@@ -29,24 +28,6 @@ class HttpRequestImpl implements HttpRequestBase {
var
bytes
=
await
request
.
bodyBytes
.
toBytes
();
html
.
HttpRequest
xhr
;
// if (request.files != null) {
// var data = html.FormData();
// if (request.files != null) {
// for (MultipartFile element in request.files) {
// var stream = element.finalize();
// data.appendBlob(element., html.File(element.finalize(),
// element.filename),
// element.filename);
// }
// }
// xhr = await html.HttpRequest.request('${request.url}',
// method: request.method, sendData: data);
// } else {
// xhr = html.HttpRequest()
// ..open(request.method, '${request.url}', async: true);
// }
xhr
=
html
.
HttpRequest
()
..
open
(
request
.
method
,
'
${request.url}
'
,
async:
true
);
// check this
...
...
@@ -68,19 +49,7 @@ class HttpRequestImpl implements HttpRequestBase {
final
stringBody
=
await
bodyBytesToString
(
bodyBytes
,
xhr
.
responseHeaders
);
T
body
;
try
{
if
(
request
.
decoder
==
null
)
{
body
=
jsonDecode
(
stringBody
)
as
T
;
}
else
{
body
=
request
.
decoder
(
jsonDecode
(
stringBody
));
}
// body = request.decoder(stringBody);
}
on
Exception
catch
(
_
)
{
body
=
stringBody
as
T
;
}
// final body = jsonDecode(stringBody);
final
body
=
bodyDecoded
<
T
>(
request
,
stringBody
);
final
response
=
Response
<
T
>(
bodyBytes:
bodyBytes
,
...
...
lib/get_connect/http/src/http_impl/http_request_io.dart
View file @
20357e4
import
'dart:convert'
;
import
'dart:io'
as
io
;
import
'../certificates/certificates.dart'
;
import
'../exceptions/exceptions.dart'
;
import
'../request/request.dart'
;
import
'../response/response.dart'
;
import
'body_decoder.dart'
;
import
'request_base.dart'
;
/// A `dart:io` implementation of `HttpRequestBase`.
...
...
@@ -50,19 +50,9 @@ class HttpRequestImpl extends HttpRequestBase {
});
final
bodyBytes
=
BodyBytes
(
response
);
final
stringBody
=
await
bodyBytesToString
(
bodyBytes
,
headers
);
T
body
;
try
{
if
(
request
.
decoder
==
null
)
{
body
=
jsonDecode
(
stringBody
)
as
T
;
}
else
{
body
=
request
.
decoder
(
jsonDecode
(
stringBody
));
}
}
on
Exception
catch
(
_
)
{
body
=
stringBody
as
T
;
}
final
body
=
bodyDecoded
<
T
>(
request
,
stringBody
);
return
Response
(
headers:
headers
,
...
...
Please
register
or
login
to post a comment