Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c685cb80
Commit
c685cb80
authored
Nov 10, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix analyzer warnings in mojo_client.dart
parent
953f1904
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
mojo_client.dart
packages/flutter/lib/src/http/mojo_client.dart
+12
-18
response.dart
packages/flutter/lib/src/http/response.dart
+3
-2
No files found.
packages/flutter/lib/src/http/mojo_client.dart
View file @
c685cb80
...
...
@@ -2,19 +2,16 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library
base_client
;
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:typed_data'
;
import
'package:flutter/src/services/shell.dart'
;
import
'package:mojo_services/mojo/network_service.mojom.dart'
as
mojo
;
import
'package:mojo_services/mojo/url_loader.mojom.dart'
as
mojo
;
import
'package:mojo/core.dart'
as
mojo
;
import
'package:mojo/mojo/url_request.mojom.dart'
as
mojo
;
import
'package:mojo/mojo/url_response.mojom.dart'
as
mojo
;
import
'package:mojo_services/mojo/network_service.mojom.dart'
as
mojo
;
import
'package:mojo_services/mojo/url_loader.mojom.dart'
as
mojo
;
import
'package:flutter/src/services/shell.dart'
;
import
'response.dart'
;
...
...
@@ -74,32 +71,29 @@ class MojoClient {
if
(
body
!=
null
)
{
mojo
.
MojoDataPipe
pipe
=
new
mojo
.
MojoDataPipe
();
request
.
body
=
<
mojo
.
MojoDataPipeConsumer
>[
pipe
.
consumer
];
ByteData
data
=
new
ByteData
.
view
(
UTF8
.
encode
(
body
).
buffer
);
Uint8List
encodedBody
=
UTF8
.
encode
(
body
);
ByteData
data
=
new
ByteData
.
view
(
encodedBody
.
buffer
);
mojo
.
DataPipeFiller
.
fillHandle
(
pipe
.
producer
,
data
);
}
try
{
_networkService
.
ptr
.
createUrlLoader
(
loader
);
mojo
.
UrlResponse
response
=
(
await
loader
.
ptr
.
start
(
request
)).
response
;
ByteData
data
=
await
mojo
.
DataPipeDrainer
.
drainHandle
(
response
.
body
);
Uint8List
body
AsList
=
new
Uint8List
.
view
(
data
.
buffer
);
String
body
AsString
=
new
String
.
fromCharCodes
(
bodyAsList
);
return
new
Response
(
body
AsString
,
response
.
statusCode
);
Uint8List
body
Bytes
=
new
Uint8List
.
view
(
data
.
buffer
);
String
body
=
new
String
.
fromCharCodes
(
bodyBytes
);
return
new
Response
(
body
:
body
,
bodyBytes:
bodyBytes
,
statusCode:
response
.
statusCode
);
}
catch
(
e
)
{
print
(
"NetworkService unavailable
$e
"
);
return
new
Response
(
null
,
500
);
return
new
Response
(
statusCode:
500
);
}
finally
{
loader
.
close
();
}
}
void
_checkResponseSuccess
(
url
,
Response
response
)
{
if
(
response
.
statusCode
<
400
)
return
;
var
message
=
"Request to
$url
failed with status
${response.statusCode}
"
;
if
(
response
.
reasonPhrase
!=
null
)
{
message
=
"
$message
:
${response.reasonPhrase}
"
;
}
if
(
url
is
String
)
url
=
Uri
.
parse
(
url
);
throw
new
ClientException
(
"
$message
."
,
url
);
if
(
response
.
statusCode
<
400
)
return
;
throw
new
Exception
(
"Request to
$url
failed with status
${response.statusCode}
."
);
}
void
close
()
{}
...
...
packages/flutter/lib/src/http/response.dart
View file @
c685cb80
...
...
@@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library
response
;
import
'dart:typed_data'
;
/// An HTTP response where the entire response body is known in advance.
class
Response
{
const
Response
(
this
.
body
,
this
.
statusCode
);
const
Response
(
{
this
.
body
,
this
.
bodyBytes
,
this
.
statusCode
}
);
final
String
body
;
final
Uint8List
bodyBytes
;
final
int
statusCode
;
}
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