<commit_before>vcl 4.0;

backend default {
  .host = "nginx";
  .port = "5003";
}

acl app {
  "app";
  "worker";
}

#sub vcl_fetch {
#    set obj.ttl = 1m;
#}

sub vcl_recv {
  # Happens before we check if we have this in cache already.
  #
  # Typically you clean up the request here, removing cookies you don't need,
  # rewriting the request, etc.
  # set req.backend = default;

  if (req.method == "PURGE") {
    if (!client.ip ~ app) {
      return (synth(405, "Not allowed."));
    }

    return (purge);
  }

  set req.http.X-Forwarded-For = client.ip;

  # Only cache GET or HEAD requests. This makes sure the POST requests are always passed.
  if (req.method != "GET" && req.method != "HEAD") {
    return (pass);
  }

  # The endpoints change their content based on ip, etc. Never cache them.
  if (req.url ~ "^/banned/" || req.url ~ "^/verify/" || req.url ~ "^/post/" || req.url ~ "^/post_manage/") {
    return (pass);
  }

  # Remove verification cookie from client
  # The verification cookie has been designed to not interfere with any requests,
  # except for /verify/ and POST requests, which are never cached.
  set req.http.Cookie = regsuball(req.http.Cookie, "verification=[^;]+(; )?", "");

  # Remove a ";" prefix in the cookie if present
  set req.http.Cookie = regsuball(req.http.Cookie, "^;\s*", "");

  # Are there cookies left with only spaces or that are empty?
  if (req.http.cookie ~ "^\s*$") {
    unset req.http.cookie;
  }
}

sub vcl_backend_response {
  set beresp.grace = 10m;
}

<commit_msg>Make varnish forward the x forwarded for header.<commit_after>vcl 4.0;

backend default {
  .host = "nginx";
  .port = "5003";
}

acl app {
  "app";
  "worker";
}

#sub vcl_fetch {
#    set obj.ttl = 1m;
#}

sub vcl_recv {
  # Happens before we check if we have this in cache already.
  #
  # Typically you clean up the request here, removing cookies you don't need,
  # rewriting the request, etc.
  # set req.backend = default;

  if (req.method == "PURGE") {
    if (!client.ip ~ app) {
      return (synth(405, "Not allowed."));
    }

    return (purge);
  }

  # IP forwarding.
  if (req.restarts == 0) {
    if (req.http.x-forwarded-for) {
      set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
    } else {
      set req.http.X-Forwarded-For = client.ip;
    }
  }

  # Only cache GET or HEAD requests. This makes sure the POST requests are always passed.
  if (req.method != "GET" && req.method != "HEAD") {
    return (pass);
  }

  # The endpoints change their content based on ip, etc. Never cache them.
  if (req.url ~ "^/banned/" || req.url ~ "^/verify/" || req.url ~ "^/post/" || req.url ~ "^/post_manage/") {
    return (pass);
  }

  # Remove verification cookie from client
  # The verification cookie has been designed to not interfere with any requests,
  # except for /verify/ and POST requests, which are never cached.
  set req.http.Cookie = regsuball(req.http.Cookie, "verification=[^;]+(; )?", "");

  # Remove a ";" prefix in the cookie if present
  set req.http.Cookie = regsuball(req.http.Cookie, "^;\s*", "");

  # Are there cookies left with only spaces or that are empty?
  if (req.http.cookie ~ "^\s*$") {
    unset req.http.cookie;
  }
}

sub vcl_backend_response {
  set beresp.grace = 10m;
}


{'fraction_non_alphanumeric': 0.14981729598051158, 'fraction_numerical': 0.007612667478684531, 'mean_word_length': 2.8783943329397874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2725410', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1125, 'n_words': 365}