From efcfb13e146b9e2ec1c61bbff8f84f9b94795443 Mon Sep 17 00:00:00 2001 From: Keisuke KITA Date: Tue, 12 May 2020 21:40:46 +0900 Subject: [PATCH 1/2] Change the behavior when domain is not set --- .../com/hisaichi5518/native_webview/CookieManager.kt | 3 ++- ios/Classes/CookieManager.swift | 9 ++++++--- lib/src/cookie_manager.dart | 3 --- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt b/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt index a337781..f5309aa 100644 --- a/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt +++ b/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt @@ -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 += ";" diff --git a/ios/Classes/CookieManager.swift b/ios/Classes/CookieManager.swift index c3e6795..acb162a 100644 --- a/ios/Classes/CookieManager.swift +++ b/ios/Classes/CookieManager.swift @@ -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 @@ -62,7 +62,7 @@ class CookieManager: NSObject, FlutterPlugin { url: String, name: String, value: String, - domain: String, + domain: String?, path: String, maxAge: String?, isSecure: Bool?, @@ -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 } diff --git a/lib/src/cookie_manager.dart b/lib/src/cookie_manager.dart index a8cfc6b..08ba003 100644 --- a/lib/src/cookie_manager.dart +++ b/lib/src/cookie_manager.dart @@ -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 args = { From 4ffbc2109459a04c77cd7c3c21e63a8ea4af393e Mon Sep 17 00:00:00 2001 From: Keisuke KITA Date: Tue, 12 May 2020 22:18:29 +0900 Subject: [PATCH 2/2] Remove semicolon --- .../kotlin/com/hisaichi5518/native_webview/CookieManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt b/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt index f5309aa..06f9694 100644 --- a/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt +++ b/android/src/main/kotlin/com/hisaichi5518/native_webview/CookieManager.kt @@ -63,7 +63,7 @@ class MyCookieManager(messenger: BinaryMessenger?) : MethodCallHandler { result: MethodChannel.Result ) { var cookieValue = "$name=$value; Path=$path" - if (domain != null) cookieValue += "; Domain=$domain;" + if (domain != null) cookieValue += "; Domain=$domain" if (maxAge != null) cookieValue += "; Max-Age=$maxAge" if (isSecure != null && isSecure) cookieValue += "; Secure" cookieValue += ";"