Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cookie]Change the behavior when domain is not set #53

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -62,7 +62,8 @@ class MyCookieManager(messenger: BinaryMessenger?) : MethodCallHandler {
isSecure: Boolean?,
result: MethodChannel.Result
) {
var cookieValue = "$name=$value; Domain=$domain; Path=$path"
var cookieValue = "$name=$value; Path=$path"
if (domain != null) cookieValue += "; Domain=$domain"
if (maxAge != null) cookieValue += "; Max-Age=$maxAge"
if (isSecure != null && isSecure) cookieValue += "; Secure"
cookieValue += ";"
Expand Down
9 changes: 6 additions & 3 deletions ios/Classes/CookieManager.swift
Expand Up @@ -22,7 +22,7 @@ class CookieManager: NSObject, FlutterPlugin {
let url = arguments["url"] as! String
let name = arguments["name"] as! String
let value = arguments["value"] as! String
let domain = arguments["domain"] as! String
let domain = arguments["domain"] as? String
let path = arguments["path"] as! String
let maxAge = arguments["maxAge"] as? String
let isSecure = arguments["isSecure"] as? Bool
Expand Down Expand Up @@ -62,7 +62,7 @@ class CookieManager: NSObject, FlutterPlugin {
url: String,
name: String,
value: String,
domain: String,
domain: String?,
path: String,
maxAge: String?,
isSecure: Bool?,
Expand All @@ -72,9 +72,12 @@ class CookieManager: NSObject, FlutterPlugin {
properties[.originURL] = url
properties[.name] = name
properties[.value] = value
properties[.domain] = domain.hasPrefix(".") ? domain : ".\(domain)"
properties[.path] = path

if let domain = domain {
properties[.domain] = domain.hasPrefix(".") ? domain : ".\(domain)"
}

if let maxAge = maxAge {
properties[.maximumAge] = maxAge
}
Expand Down
3 changes: 0 additions & 3 deletions lib/src/cookie_manager.dart
Expand Up @@ -35,12 +35,9 @@ class CookieManager {
Duration maxAge,
bool isSecure,
}) async {
if (domain == null || domain.isEmpty) domain = _getDomainName(url);

assert(url != null && url.isNotEmpty);
assert(name != null && name.isNotEmpty);
assert(value != null && value.isNotEmpty);
assert(domain != null && domain.isNotEmpty);
assert(path != null && path.isNotEmpty);

Map<String, dynamic> args = <String, dynamic>{
Expand Down