stokito / grails-cookie

Makes dealing with cookies easy. Provides an injectable service and tag to easily get, set, and delete cookies with one line
http://grails.org/plugin/cookie
16 stars 12 forks source link

delete cookie not working at all #46

Closed akyong closed 7 years ago

akyong commented 7 years ago
def actualcookie = cookieService.getCookie("aaa")
        println "get cookie 1 = "+cookieService.getCookie("aaa")
        cookieService.deleteCookie(actualcookie)
        println "asdfas"
        println "get cookie 2 = "+cookieService.getCookie("aaa")

image

i don't know why my code is not working

stokito commented 7 years ago

Hi @gryphonest it looks ok. To delete a cookie you have to set the same cookie but with expired date. Cookie gets remived feom browser automatically when expires. Try to find additional info in web, wikipedia article about cookie should describe this as well.

Maybe i not understood you correctly, then please add some details

akyong commented 7 years ago

oh i see, i just set all my cookie to 0, but i am getting this error

Caused by: org.apache.coyote.http11.HeadersTooLargeException: An attempt was made to write more data to the response headers than there was room available in the buffer. Increase maxHttpHeaderSize on the connector or write less data into the response headers.

stokito commented 7 years ago

I never seen this an error before, so i have no idea how to help. Maybe something wrong with your code. Could you show more code? But anyway im on traveling now and writing to you from my phone so it looks like i can't help you

akyong commented 7 years ago

def deleteItemIncookie(){ def no = cookieService.getCookie('no') println "noo - "+no for(int a = 1;a<=no;a++){ cookieService.setCookie(name:"qty"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"description"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"alamatTujuan"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"item"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"province"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"city"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"kurir"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"ongkir"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"deleteFlag"+a, value: "N", maxAge: 66060, path: "/") } }

stokito commented 7 years ago

You have some for statement and maybe it causes the problem. Firts you get a cookie called 'no' and this variable stores a cookie object itself, not only its value. So then you trying to cast var no as integer and maybe Groovy compiler returned too big number. So try to write like this:

int no = cookieService.getCookie('no')?.value :? 0 println "noo - "+no for(int a = 1; a<=no; a++){

In this case you get cookie value which is a String object, then cast it to int. If cookie is null or cookie value is emty then it will be stored zero 0 to variable no This code might not working because i wrote it from my head

On Thu, Mar 16, 2017 at 22:54 Bobby notifications@github.com wrote:

` def deleteItemIncookie(){ def no = cookieService.getCookie('no') println "noo - "+no for(int a = 1;a<=no;a++){ cookieService.setCookie(name:"qty"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"description"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"alamatTujuan"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"item"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"province"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"city"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"kurir"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"ongkir"+a, value: "", maxAge: 1, path: "/") cookieService.setCookie(name:"deleteFlag"+a, value: "N", maxAge: 66060, path: "/") }

}`

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stokito/grails-cookie/issues/46#issuecomment-287082566, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZXDgHdjp3MnOa5cKpBHVBXbnXiPL5Uks5rmU0QgaJpZM4MfXY0 .

-- Sergey Ponomarev http://www.linkedin.com/in/stokito, skype: stokito

akyong commented 7 years ago

oh my god, you are right, "1" is 49

stokito commented 7 years ago

Cool. Please take my tip: try to always set a concrete type. Def is ok only for tuples, ie miltiple values returned from the method. I mean that week dynamic typing is good for DSLs but regular code should be strongly typed.

You can check a source code of the plugin to see how i used this rule. It really makes your code more safer. Also please try Intellij Idea - it shows almost all errors in Groovy. The Intellij is is free for EAP version

On Thu, Mar 16, 2017 at 23:21 Bobby notifications@github.com wrote:

oh my god, you are right, "1" is 49

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stokito/grails-cookie/issues/46#issuecomment-287091450, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZXDvDNCo4qO0vJ0ImSsrD5PojaNFJmks5rmVN2gaJpZM4MfXY0 .

-- Sergey Ponomarev http://www.linkedin.com/in/stokito, skype: stokito