@@ -4,6 +4,7 @@ package io.github.javaconductor.gserv.samples.etag
44import io.github.javaconductor.gserv.*
55import io.github.javaconductor.gserv.plugins.*
66import io.github.javaconductor.gserv.utils.Encoder
7+ import net.sf.json.JSONObject
78
89class Main {
910
@@ -27,11 +28,18 @@ class Main {
2728 get(" /" , file(" text/plain" , " data/rfile.txt" ))
2829
2930 // This will create a Base64 String for the eTag
30- strongETag( " /* " ){exch , data ->
31+ strongETag( " /" ){exch , data ->
3132 // MD5 it
3233 Encoder . md5WithBase64(data)
3334 }
3435
36+ // This will create a Base64 String for the eTag
37+ weakETag( " /answers/*" ){context , actionArgs ->
38+ // MD5 it
39+ def data = actionArgs. join(' .' ). bytes
40+ Encoder . md5WithBase64(data)
41+ }
42+
3543 get(' /answers/:op/:num1:Number/:num2:Number' ){ op , num1 , num2 ->
3644 def ans
3745 switch (op){
@@ -43,20 +51,6 @@ class Main {
4351 writeJson(ans : ans)
4452 }
4553
46- // https://github.com/javaConductor/gserv/issues/11
47- // THIS DOES NOT WORK - ONLY Context is passed.
48- // // This will create an eTag based sole on the request values
49- // // this is fine as long as a set of results always returns the same value.
50- // /// Example: when a GET is sent tot this resource like: /add/23.12/43.45, the
51- // /// response will always be 66.57
52- // weakETag( "/answers/:op/:num1/:num2"){op, num1, num2 ->
53- // Encoder.md5WithBase64("$num1_$op_$num2".bytes)
54- // }
55-
56- /* weakETag( "/answers/:op/:num1/:num2"){ context ->
57- Encoder.md5WithBase64(context.requestURI.path.bytes)
58- }
59- */
6054 }. start(54321 )
6155 }// main
6256}
0 commit comments