Advertisement
Guest User

Untitled

a guest
Nov 20th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1.  
  2. ###
  3. # Custom subroutines to provide ESI support for Drupal blocks with the
  4. # Drupal ESI module.
  5. ##
  6.  
  7. /**
  8. * Alter the hash per-user or per-role
  9. */
  10. sub esi_block__hash {
  11. # Customise the hash if required.
  12. if ( req.http.X_BLOCK_CACHE ) {
  13. if( req.http.X_BLOCK_CACHE == "USER" ) {
  14. if( req.http.Cookie ~ "SESS" ) {
  15. # This pulls the session-name and session-id from the cookie string.
  16. set req.http.X-SESSION-ID =
  17. regsub( req.http.Cookie, "^.*?SESS(.{32})=([^;]*);*.*$", "\1\2" );
  18.  
  19. # add the session info to the hash.
  20.  
  21. # 3.0
  22. hash_data(req.http.X-SESSION-ID);
  23. # 2.x
  24. #set req.hash += req.http.X-SESSION-ID;
  25. }
  26. }
  27.  
  28. if( req.http.X_BLOCK_CACHE == "ROLE" ) {
  29. # Roles are identified by a cookie beginning RSESS
  30. if( req.http.Cookie ~ "RSESS" ) {
  31. # This pulls the role info from the cookie string.
  32. set req.http.X-ROLE-SESSION-ID =
  33. regsub( req.http.Cookie, "^.*?RSESS(.{32})=([^;]*);*.*$", "\1\2" );
  34.  
  35. # add the session info to the hash.
  36.  
  37. # 3.0
  38. hash_data(req.http.X-ROLE-SESSION-ID);
  39. # 2.x
  40. #set req.hash += req.http.X-ROLE-SESSION-ID;
  41. }
  42. }
  43. }
  44. }
  45.  
  46.  
  47. /**
  48. * Add an http header if an ESI block has per-user or per-role cache rules
  49. */
  50. sub esi_block__recv {
  51.  
  52. # The URL structure of ESI blocks identifies which are per-user or per-role.
  53. # e.g. /esi/block/garland:left:foo:bar/node%2F1/CACHE=USER
  54. # Add a header to show if we're using a particular cache strategy.
  55. if ((req.url ~ "^/esi/block" ) || (req.url ~ "^/esi/panels_pane" )) {
  56.  
  57. # look for a cache instruction. This should be the final argument to the URL
  58. # and should have the value 'USER' or 'ROLE'.
  59. if ( req.url ~ "^.*/CACHE=[^/]*$" ) {
  60.  
  61. # Set an HTTP_X_BLOCK_CACHE header to be appropriate setting.
  62. set req.http.X_BLOCK_CACHE =
  63. regsub( req.url, "^.*/CACHE=([^/]*)$", "\1" );
  64.  
  65. # Strip the cache-instruction from the end of the URL.
  66. set req.url =
  67. regsub( req.url, "^(.*)/CACHE=[^/]*$", "\1" );
  68. }
  69. }
  70.  
  71. # Ignore presence of cookies, etc, for ESI requests:
  72. # Always try to lookup ESIs from the cache.
  73. if(req.url ~ "^/esi.*") {
  74. # 3.0
  75. return (lookup);
  76. # 2.x
  77. #lookup;
  78. }
  79. }
  80.  
  81.  
  82. /**
  83. * Cache ESI'd block content.
  84. */
  85. sub esi_block__fetch {
  86. # ESI blocks with per-user or per-role config have a cache-control: private
  87. # header. This removes the header and inserts the block into the cache.
  88.  
  89. # 3.0
  90. if( beresp.http.Cache-Control ~ "private" ) {
  91. unset beresp.http.Set-Cookie;
  92. unset beresp.http.Cache-Control;
  93. return (deliver);
  94. }
  95. # 2.x
  96. #if( obj.http.Cache-Control ~ "private" ) {
  97. # unset obj.http.Set-Cookie;
  98. # unset obj.http.Cache-Control;
  99. # deliver;
  100. #}
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement