Skip to content

Commit 85a7177

Browse files
authored
Merge pull request #81 from chrbayer/master
Make automatic sending of sessionId optional.
2 parents 88f0b80 + daf8aca commit 85a7177

9 files changed

+69
-21
lines changed

lib/parse_server_sdk.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Parse {
7979
String clientKey,
8080
String masterKey,
8181
String sessionId,
82+
bool autoSendSessionId,
8283
SecurityContext securityContext}) {
8384
ParseCoreData.init(appId, serverUrl,
8485
debug: debug,
@@ -87,6 +88,7 @@ class Parse {
8788
masterKey: masterKey,
8889
clientKey: clientKey,
8990
sessionId: sessionId,
91+
autoSendSessionId: autoSendSessionId,
9092
securityContext: securityContext);
9193

9294
_hasBeenInitialized = true;
@@ -97,12 +99,15 @@ class Parse {
9799
bool hasParseBeenInitialized() => _hasBeenInitialized;
98100

99101
Future<ParseResponse> healthCheck(
100-
{bool debug, ParseHTTPClient client}) async {
102+
{bool debug, ParseHTTPClient client, bool autoSendSessionId}) async {
101103
ParseResponse parseResponse;
102104

103105
bool _debug = isDebugEnabled(objectLevelDebug: debug);
104-
ParseHTTPClient _client =
105-
client ?? ParseHTTPClient(ParseCoreData().securityContext);
106+
ParseHTTPClient _client = client ??
107+
ParseHTTPClient(
108+
autoSendSessionId:
109+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
110+
securityContext: ParseCoreData().securityContext);
106111

107112
try {
108113
var response =

lib/src/data/parse_core_data.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ParseCoreData {
1717
masterKey,
1818
clientKey,
1919
sessionId,
20+
autoSendSessionId,
2021
securityContext}) {
2122
_instance = ParseCoreData._init(appId, serverUrl);
2223

@@ -26,6 +27,8 @@ class ParseCoreData {
2627
if (clientKey != null) _instance.clientKey = clientKey;
2728
if (masterKey != null) _instance.masterKey = masterKey;
2829
if (sessionId != null) _instance.sessionId = sessionId;
30+
if (autoSendSessionId != null)
31+
_instance.autoSendSessionId = autoSendSessionId;
2932
if (securityContext != null) _instance.securityContext = securityContext;
3033
}
3134

@@ -36,6 +39,7 @@ class ParseCoreData {
3639
String masterKey;
3740
String clientKey;
3841
String sessionId;
42+
bool autoSendSessionId;
3943
SecurityContext securityContext;
4044
bool debug;
4145
SharedPreferences storage;

lib/src/network/parse_http_client.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ part of flutter_parse_sdk;
33
/// Creates a custom version of HTTP Client that has Parse Data Preset
44
class ParseHTTPClient extends BaseClient {
55
final Client _client;
6+
final bool _autoSendSessionId;
67
final String _userAgent = "$keyLibraryName $keySdkVersion";
78
ParseCoreData data = ParseCoreData();
89
Map<String, String> additionalHeaders;
910

10-
ParseHTTPClient([SecurityContext securityContext])
11-
: _client = securityContext != null
11+
ParseHTTPClient(
12+
{bool autoSendSessionId = false, SecurityContext securityContext})
13+
: _autoSendSessionId = autoSendSessionId,
14+
_client = securityContext != null
1215
? IOClient(HttpClient(context: securityContext))
1316
: IOClient();
1417

@@ -17,7 +20,8 @@ class ParseHTTPClient extends BaseClient {
1720
Future<StreamedResponse> send(BaseRequest request) {
1821
request.headers[keyHeaderUserAgent] = _userAgent;
1922
request.headers[keyHeaderApplicationId] = data.applicationId;
20-
if ((data.sessionId != null) &&
23+
if ((_autoSendSessionId == true) &&
24+
(data.sessionId != null) &&
2125
(request.headers[keyHeaderSessionToken] == null))
2226
request.headers[keyHeaderSessionToken] = data.sessionId;
2327

lib/src/objects/parse_config.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ part of flutter_parse_sdk;
22

33
class ParseConfig extends ParseObject {
44
/// Creates an instance of ParseConfig so that you can grab all configs from the server
5-
ParseConfig({bool debug, ParseHTTPClient client}) : super('config') {
5+
ParseConfig({bool debug, ParseHTTPClient client, bool autoSendSessionId})
6+
: super('config') {
67
_debug = isDebugEnabled(objectLevelDebug: debug);
7-
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
8+
_client = client ??
9+
ParseHTTPClient(
10+
autoSendSessionId:
11+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
12+
securityContext: ParseCoreData().securityContext);
813
}
914

1015
/// Gets all configs from the server

lib/src/objects/parse_file.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ class ParseFile extends ParseObject {
2121
///
2222
/// {https://docs.parseplatform.org/rest/guide/#files/}
2323
ParseFile(this.file,
24-
{String name, String url, bool debug, ParseHTTPClient client})
24+
{String name,
25+
String url,
26+
bool debug,
27+
ParseHTTPClient client,
28+
bool autoSendSessionId})
2529
: super(keyFile) {
2630
_debug = isDebugEnabled(objectLevelDebug: debug);
27-
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
31+
_client = client ??
32+
ParseHTTPClient(
33+
autoSendSessionId:
34+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
35+
securityContext: ParseCoreData().securityContext);
2836

2937
if (file != null) {
3038
this.name = path.basename(file.path);

lib/src/objects/parse_function.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ class ParseCloudFunction extends ParseObject {
99
/// Creates a new cloud function object
1010
///
1111
/// {https://docs.parseplatform.org/cloudcode/guide/}
12-
ParseCloudFunction(this.functionName, {bool debug, ParseHTTPClient client})
12+
ParseCloudFunction(this.functionName,
13+
{bool debug, ParseHTTPClient client, bool autoSendSessionId})
1314
: super(functionName) {
1415
_path = "/functions/$functionName";
1516

1617
_debug = isDebugEnabled(objectLevelDebug: debug);
17-
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
18+
_client = client ??
19+
ParseHTTPClient(
20+
autoSendSessionId:
21+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
22+
securityContext: ParseCoreData().securityContext);
1823
}
1924

2025
/// Executes a cloud function

lib/src/objects/parse_geo_point.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ class ParseGeoPoint extends ParseObject {
99
{double latitude = 0.0,
1010
double longitude = 0.0,
1111
bool debug,
12-
ParseHTTPClient client})
12+
ParseHTTPClient client,
13+
bool autoSendSessionId})
1314
: super(keyGeoPoint) {
1415
_latitude = latitude;
1516
_longitude = longitude;
1617

1718
_debug = isDebugEnabled(objectLevelDebug: debug);
18-
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
19+
_client = client ??
20+
ParseHTTPClient(
21+
autoSendSessionId:
22+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
23+
securityContext: ParseCoreData().securityContext);
1924
}
2025

2126
double get latitude => _latitude;

lib/src/objects/parse_object.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ class ParseObject extends ParseBase implements ParseCloneable {
1515
/// [String] className refers to the Table Name in your Parse Server,
1616
/// [bool] debug will overwrite the current default debug settings and
1717
/// [ParseHttpClient] can be overwritten to create your own HTTP Client
18-
ParseObject(String className, {bool debug: false, ParseHTTPClient client})
18+
ParseObject(String className,
19+
{bool debug: false, ParseHTTPClient client, bool autoSendSessionId})
1920
: super() {
2021
setClassName(className);
2122
_path = "$keyEndPointClasses$className";
2223

2324
_debug = isDebugEnabled(objectLevelDebug: debug);
24-
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
25+
_client = client ??
26+
ParseHTTPClient(
27+
autoSendSessionId:
28+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
29+
securityContext: ParseCoreData().securityContext);
2530
}
2631

2732
String toPointer() => parseEncode(this);

lib/src/objects/parse_user.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
4444
{bool debug, ParseHTTPClient client})
4545
: super(keyClassUser) {
4646
_debug = isDebugEnabled(objectLevelDebug: debug);
47-
_client = client ?? ParseHTTPClient(ParseCoreData().securityContext);
47+
_client = client ??
48+
ParseHTTPClient(
49+
autoSendSessionId: true,
50+
securityContext: ParseCoreData().securityContext);
4851

4952
this.username = username;
5053
this.password = password;
@@ -65,8 +68,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
6568
static Future<ParseResponse> getCurrentUserFromServer(
6669
{String token, bool debug, ParseHTTPClient client}) async {
6770
bool _debug = isDebugEnabled(objectLevelDebug: debug);
68-
ParseHTTPClient _client =
69-
client ?? ParseHTTPClient(ParseCoreData().securityContext);
71+
ParseHTTPClient _client = client ??
72+
ParseHTTPClient(
73+
autoSendSessionId: true,
74+
securityContext: ParseCoreData().securityContext);
7075

7176
// We can't get the current user and session without a sessionId
7277
if ((ParseCoreData().sessionId == null) && (token == null)) {
@@ -272,8 +277,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
272277
var emptyUser = ParseUser(null, null, null);
273278

274279
bool _debug = isDebugEnabled(objectLevelDebug: debug);
275-
ParseHTTPClient _client =
276-
client ?? ParseHTTPClient(ParseCoreData().securityContext);
280+
ParseHTTPClient _client = client ??
281+
ParseHTTPClient(
282+
autoSendSessionId: true,
283+
securityContext: ParseCoreData().securityContext);
277284

278285
try {
279286
final response = await _client.get("${ParseCoreData().serverUrl}/$path");

0 commit comments

Comments
 (0)