Remove redundant fetch functions and avoid crashing when no headers are set
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/http.dart' as http;
|
||||
|
||||
final math.Random _rng = new math.Random();
|
||||
|
||||
@@ -83,8 +83,8 @@ class StockDataFetcher {
|
||||
if (!actuallyFetchData)
|
||||
return;
|
||||
|
||||
fetchBody(_urlToFetch(_nextChunk++)).then((Response response) {
|
||||
String json = response.bodyAsString();
|
||||
http.get(_urlToFetch(_nextChunk++)).then((http.Response response) {
|
||||
String json = response.body;
|
||||
if (json == null) {
|
||||
print("Failed to load stock data chunk ${_nextChunk - 1}");
|
||||
return;
|
||||
|
||||
@@ -66,7 +66,7 @@ class MojoClient {
|
||||
Map<String, String> headers, [body, Encoding encoding]) async {
|
||||
mojo.UrlLoaderProxy loader = new mojo.UrlLoaderProxy.unbound();
|
||||
List<mojo.HttpHeader> mojoHeaders = <mojo.HttpHeader>[];
|
||||
headers.forEach((String name, String value) {
|
||||
headers?.forEach((String name, String value) {
|
||||
mojo.HttpHeader header = new mojo.HttpHeader()
|
||||
..name = name
|
||||
..value = value;
|
||||
|
||||
@@ -7,6 +7,8 @@ import 'dart:ui' as ui;
|
||||
import 'dart:ui_internals' as internals;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/http.dart' as http;
|
||||
|
||||
import 'package:mojo/core.dart' as core;
|
||||
import 'package:mojo_services/mojo/asset_bundle/asset_bundle.mojom.dart';
|
||||
|
||||
@@ -38,7 +40,7 @@ class NetworkAssetBundle extends AssetBundle {
|
||||
|
||||
ImageResource loadImage(String key) => imageCache.load(_urlFromKey(key));
|
||||
|
||||
Future<String> loadString(String key) => fetchString(_urlFromKey(key));
|
||||
Future<String> loadString(String key) => http.get(_urlFromKey(key));
|
||||
}
|
||||
|
||||
Future _fetchAndUnpackBundle(String relativeUrl, AssetBundleProxy bundle) async {
|
||||
|
||||
@@ -23,18 +23,6 @@ NetworkServiceProxy _initNetworkService() {
|
||||
|
||||
final NetworkServiceProxy _networkService = _initNetworkService();
|
||||
|
||||
class Response {
|
||||
ByteData body;
|
||||
|
||||
Response(this.body);
|
||||
|
||||
String bodyAsString() {
|
||||
if (body == null)
|
||||
return null;
|
||||
return new String.fromCharCodes(new Uint8List.view(body.buffer));
|
||||
}
|
||||
}
|
||||
|
||||
Future<UrlResponse> fetch(UrlRequest request) async {
|
||||
UrlLoaderProxy loader = new UrlLoaderProxy.unbound();
|
||||
try {
|
||||
@@ -56,16 +44,3 @@ Future<UrlResponse> fetchUrl(String relativeUrl) {
|
||||
..autoFollowRedirects = true;
|
||||
return fetch(request);
|
||||
}
|
||||
|
||||
Future<Response> fetchBody(String relativeUrl) async {
|
||||
UrlResponse response = await fetchUrl(relativeUrl);
|
||||
if (response.body == null) return new Response(null);
|
||||
|
||||
ByteData data = await core.DataPipeDrainer.drainHandle(response.body);
|
||||
return new Response(data);
|
||||
}
|
||||
|
||||
Future<String> fetchString(String relativeUrl) async {
|
||||
Response response = await fetchBody(relativeUrl);
|
||||
return response.bodyAsString();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:mojo/core.dart';
|
||||
import 'package:flutter/http.dart' as http;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flx/bundle.dart';
|
||||
import 'package:sky_services/updater/update_service.mojom.dart';
|
||||
@@ -82,7 +83,7 @@ class UpdateTask {
|
||||
|
||||
Future<yaml.YamlMap> _fetchManifest() async {
|
||||
String manifestUrl = _currentManifest['update-url'] + '/' + kManifestFile;
|
||||
String manifestData = await fetchString(manifestUrl);
|
||||
String manifestData = await http.get(manifestUrl);
|
||||
return yaml.loadYaml(manifestData, sourceUrl: manifestUrl);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user