You are here

datadome_integration_fetch.html.twig in Fastly 8.3

if (req.backend == datadome) {
declare local var.status STRING;
set var.status = beresp.status;
# check that it is real ApiServer response
if (var.status != beresp.http.x-datadomeresponse) {
restart;
}
unset beresp.http.x-datadomeresponse;
# copy datadome headers
set req.http.x-datadome-headers-pairs:x-datadome-headers = urlencode(beresp.http.x-datadome-headers);

if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-set-cookie( |$)+") {
set req.http.x-datadome-headers-pairs:x-set-cookie = urlencode(beresp.http.x-set-cookie);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-datadome-server( |$)+") {
set req.http.x-datadome-headers-pairs:x-datadome-server = urlencode(beresp.http.x-datadome-server);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-datadome( |$)+") {
set req.http.x-datadome-headers-pairs:x-datadome = urlencode(beresp.http.x-datadome);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+content-type( |$)+") {
set req.http.x-datadome-headers-pairs:content-type = urlencode(beresp.http.content-type);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+charset( |$)+") {
set req.http.x-datadome-headers-pairs:charset = urlencode(beresp.http.charset);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+cache-control( |$)+") {
set req.http.x-datadome-headers-pairs:cache-control = urlencode(beresp.http.cache-control);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+pragma( |$)+") {
set req.http.x-datadome-headers-pairs:pragma = urlencode(beresp.http.pragma);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+access-control-allow-credentials( |$)+") {
set req.http.x-datadome-headers-pairs:access-control-allow-credentials = urlencode(beresp.http.access-control-allow-credentials);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+access-control-expose-headers( |$)+") {
set req.http.x-datadome-headers-pairs:access-control-expose-headers = urlencode(beresp.http.access-control-expose-headers);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+access-control-allow-origin( |$)+") {
set req.http.x-datadome-headers-pairs:access-control-allow-origin = urlencode(beresp.http.access-control-allow-origin);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-datadome-cid( |$)+") {
set req.http.x-datadome-headers-pairs:x-datadome-cid = urlencode(beresp.http.x-datadome-cid);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-dd-b( |$)+") {
set req.http.x-datadome-headers-pairs:x-dd-b = urlencode(beresp.http.x-dd-b);
}
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-dd-type( |$)+") {
set req.http.x-datadome-headers-pairs:x-dd-type = urlencode(beresp.http.x-dd-type);
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-dd-type( |$)+") {
set req.http.x-dd-type = beresp.http.x-dd-type;
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botname( |$)+") {
set req.http.x-datadome-botname = beresp.http.x-datadome-botname;
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botfamily( |$)+") {
set req.http.x-datadome-botfamily = beresp.http.x-datadome-botfamily;
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-isbot( |$)+") {
set req.http.x-datadome-isbot = beresp.http.x-datadome-isbot;
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-captchapassed( |$)+") {
set req.http.x-datadome-captchapassed = beresp.http.x-datadome-captchapassed;
}
# don't forget about ApiServer's cookies
if (beresp.http.x-datadome-headers ~ "(?i)(^| )+set-cookie( |$)+") {
set req.http.x-datadome-headers-pairs:set-cookie = urlencode(beresp.http.set-cookie);
}

# Continue only if ApiServer returns expected blocked status
if (beresp.status != 403 && beresp.status != 401 && beresp.status != 301 && beresp.status != 302) {
unset beresp.http.x-datadome-headers;
unset beresp.http.x-datadome-request-headers;
restart;
}

# ok, it is banned request, cleanup it a bit
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-dd-type( |$)+") {
if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-dd-type( |$)+") {
unset beresp.http.x-dd-type;
}
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botname( |$)+") {
if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-botname( |$)+") {
unset beresp.http.x-datadome-botname;
}
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botfamily( |$)+") {
if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-botfamily( |$)+") {
unset beresp.http.x-datadome-botfamily;
}
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-isbot( |$)+") {
if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-isbot( |$)+") {
unset beresp.http.x-datadome-isbot;
}
}
if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-captchapassed( |$)+") {
if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-captchapassed( |$)+") {
unset beresp.http.x-datadome-captchapassed;
}
}
unset beresp.http.x-datadome-headers;
unset beresp.http.x-datadome-request-headers;
}

File

fastly_edge_modules/templates/datadome_integration_fetch.html.twig
View source
  1. if (req.backend == datadome) {
  2. declare local var.status STRING;
  3. set var.status = beresp.status;
  4. # check that it is real ApiServer response
  5. if (var.status != beresp.http.x-datadomeresponse) {
  6. restart;
  7. }
  8. unset beresp.http.x-datadomeresponse;
  9. # copy datadome headers
  10. set req.http.x-datadome-headers-pairs:x-datadome-headers = urlencode(beresp.http.x-datadome-headers);
  11. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-set-cookie( |$)+") {
  12. set req.http.x-datadome-headers-pairs:x-set-cookie = urlencode(beresp.http.x-set-cookie);
  13. }
  14. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-datadome-server( |$)+") {
  15. set req.http.x-datadome-headers-pairs:x-datadome-server = urlencode(beresp.http.x-datadome-server);
  16. }
  17. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-datadome( |$)+") {
  18. set req.http.x-datadome-headers-pairs:x-datadome = urlencode(beresp.http.x-datadome);
  19. }
  20. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+content-type( |$)+") {
  21. set req.http.x-datadome-headers-pairs:content-type = urlencode(beresp.http.content-type);
  22. }
  23. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+charset( |$)+") {
  24. set req.http.x-datadome-headers-pairs:charset = urlencode(beresp.http.charset);
  25. }
  26. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+cache-control( |$)+") {
  27. set req.http.x-datadome-headers-pairs:cache-control = urlencode(beresp.http.cache-control);
  28. }
  29. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+pragma( |$)+") {
  30. set req.http.x-datadome-headers-pairs:pragma = urlencode(beresp.http.pragma);
  31. }
  32. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+access-control-allow-credentials( |$)+") {
  33. set req.http.x-datadome-headers-pairs:access-control-allow-credentials = urlencode(beresp.http.access-control-allow-credentials);
  34. }
  35. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+access-control-expose-headers( |$)+") {
  36. set req.http.x-datadome-headers-pairs:access-control-expose-headers = urlencode(beresp.http.access-control-expose-headers);
  37. }
  38. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+access-control-allow-origin( |$)+") {
  39. set req.http.x-datadome-headers-pairs:access-control-allow-origin = urlencode(beresp.http.access-control-allow-origin);
  40. }
  41. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-datadome-cid( |$)+") {
  42. set req.http.x-datadome-headers-pairs:x-datadome-cid = urlencode(beresp.http.x-datadome-cid);
  43. }
  44. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-dd-b( |$)+") {
  45. set req.http.x-datadome-headers-pairs:x-dd-b = urlencode(beresp.http.x-dd-b);
  46. }
  47. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+x-dd-type( |$)+") {
  48. set req.http.x-datadome-headers-pairs:x-dd-type = urlencode(beresp.http.x-dd-type);
  49. }
  50. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-dd-type( |$)+") {
  51. set req.http.x-dd-type = beresp.http.x-dd-type;
  52. }
  53. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botname( |$)+") {
  54. set req.http.x-datadome-botname = beresp.http.x-datadome-botname;
  55. }
  56. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botfamily( |$)+") {
  57. set req.http.x-datadome-botfamily = beresp.http.x-datadome-botfamily;
  58. }
  59. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-isbot( |$)+") {
  60. set req.http.x-datadome-isbot = beresp.http.x-datadome-isbot;
  61. }
  62. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-captchapassed( |$)+") {
  63. set req.http.x-datadome-captchapassed = beresp.http.x-datadome-captchapassed;
  64. }
  65. # don't forget about ApiServer's cookies
  66. if (beresp.http.x-datadome-headers ~ "(?i)(^| )+set-cookie( |$)+") {
  67. set req.http.x-datadome-headers-pairs:set-cookie = urlencode(beresp.http.set-cookie);
  68. }
  69. # Continue only if ApiServer returns expected blocked status
  70. if (beresp.status != 403 && beresp.status != 401 && beresp.status != 301 && beresp.status != 302) {
  71. unset beresp.http.x-datadome-headers;
  72. unset beresp.http.x-datadome-request-headers;
  73. restart;
  74. }
  75. # ok, it is banned request, cleanup it a bit
  76. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-dd-type( |$)+") {
  77. if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-dd-type( |$)+") {
  78. unset beresp.http.x-dd-type;
  79. }
  80. }
  81. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botname( |$)+") {
  82. if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-botname( |$)+") {
  83. unset beresp.http.x-datadome-botname;
  84. }
  85. }
  86. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-botfamily( |$)+") {
  87. if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-botfamily( |$)+") {
  88. unset beresp.http.x-datadome-botfamily;
  89. }
  90. }
  91. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-isbot( |$)+") {
  92. if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-isbot( |$)+") {
  93. unset beresp.http.x-datadome-isbot;
  94. }
  95. }
  96. if (beresp.http.x-datadome-request-headers ~ "(?i)(^| )+x-datadome-captchapassed( |$)+") {
  97. if (beresp.http.x-datadome-headers !~ "(?i)(^| )+x-datadome-captchapassed( |$)+") {
  98. unset beresp.http.x-datadome-captchapassed;
  99. }
  100. }
  101. unset beresp.http.x-datadome-headers;
  102. unset beresp.http.x-datadome-request-headers;
  103. }