11import 'dart:async' ;
22import 'dart:convert' ;
33
4+ import 'package:contentstack/constant.dart' ;
45import 'package:contentstack/contentstack.dart' ;
56import 'package:contentstack/src/stack.dart' ;
67import 'package:http/http.dart' as http;
@@ -9,8 +10,6 @@ class HttpClient extends http.BaseClient {
910 final http.Client _client;
1011 final Stack stack;
1112 final Map <String , String > stackHeaders;
12- // Request timout period 30 Seconds
13- static const timeout = 30 ;
1413
1514 factory HttpClient (Map <String , String > headers,
1615 {http.Client client, Stack stack}) {
@@ -29,11 +28,11 @@ class HttpClient extends http.BaseClient {
2928 }
3029
3130 Future <T > sendRequest <T , K >(Uri uri) async {
32- stackHeaders['Content-Type' ] = 'application/json' ;
33- stackHeaders['X-User-Agent' ] = 'contentstack-dart/0.1.1' ;
31+ stackHeaders[CONTENT_TYPE ] = CONTENT_TYPE_VALUE ;
32+ stackHeaders[X_USER_AGENT ] = X_USER_AGENT_VALUE ;
3433 final response = await http
3534 .get (uri, headers: stackHeaders)
36- .timeout (const Duration (seconds: timeout ));
35+ .timeout (const Duration (seconds: TIMEOUT ));
3736 Object bodyJson;
3837 try {
3938 bodyJson = jsonDecode (response.body);
@@ -46,7 +45,8 @@ class HttpClient extends http.BaseClient {
4645 rethrow ;
4746 }
4847 if (response.statusCode == 200 ) {
49- final Map bodyJson = jsonDecode (response.body);
48+ // Decode response to Utf8Codec
49+ final Map bodyJson = json.decode (utf8.decode (response.bodyBytes));
5050 if (T == EntryModel && bodyJson.containsKey ('entry' )) {
5151 return fromJson <T , K >(bodyJson['entry' ]);
5252 } else if (K == EntryModel && bodyJson.containsKey ('entries' )) {
@@ -61,6 +61,7 @@ class HttpClient extends http.BaseClient {
6161 return fromJson <T , K >(bodyJson);
6262 }
6363 } else {
64+ // Response code other than 200
6465 return bodyJson;
6566 }
6667 }
0 commit comments