<commit_before>vcl 4.0;

<% node['cxn']['domains'].each do |config| -%>
backend s3_<%= config.id %> {
    .host = "s3.<%= config.bucket_region %>.amazonaws.com";
    .port = "80";
    .connect_timeout = 5s;
    .first_byte_timeout = 10s;
    .between_bytes_timeout = 10s;
}
<% end -%>

sub vcl_recv {
<% node['cxn']['domains'].each do |config| -%>
    if (req.http.host == "<%= config.domain %>") {
      set req.http.host = "<%= config.bucket %>.s3.amazonaws.com";
      set req.backend_hint = s3_<%= config.id %>;
    }
<% end -%>
    set req.url = regsub(req.url, "\?.*", "");

    if (req.method == "DELETE") {
        ban("obj.http.x-url ~ " + req.url);
        return (synth(200, "OK"));
    }

    if (req.url == "/health" || req.url == "/"){
        return (synth(200, "OK"));
    }

    # remove headers from request
    unset req.http.cookie;
    unset req.http.cache-control;
    unset req.http.pragma;
    unset req.http.expires;
    unset req.http.etag;
    unset req.http.X-Forwarded-For;
}

sub vcl_synth {
  if (resp.status == 200 && req.url ~ "^/$") {
      synthetic("");
      return (deliver);
  }
}
<commit_msg>improve static responses from varnish<commit_after>vcl 4.0;

<% node['cxn']['domains'].each do |config| -%>
backend s3_<%= config.id %> {
    .host = "s3.<%= config.bucket_region %>.amazonaws.com";
    .port = "80";
    .connect_timeout = 5s;
    .first_byte_timeout = 10s;
    .between_bytes_timeout = 10s;
}
<% end -%>

sub vcl_recv {
<% node['cxn']['domains'].each do |config| -%>
    if (req.http.host == "<%= config.domain %>") {
      set req.http.host = "<%= config.bucket %>.s3.amazonaws.com";
      set req.backend_hint = s3_<%= config.id %>;
    }
<% end -%>
    set req.url = regsub(req.url, "\?.*", "");

    if (req.method == "DELETE") {
        ban("obj.http.x-url ~ " + req.url);
        return (synth(200, "OK"));
    }

    if (req.url == "/health" || req.url == "/"){
        return (synth(200, "OK"));
    }

    # remove headers from request
    unset req.http.cookie;
    unset req.http.cache-control;
    unset req.http.pragma;
    unset req.http.expires;
    unset req.http.etag;
    unset req.http.X-Forwarded-For;
}

sub vcl_synth {
    if (resp.status == 200 && req.url ~ "^/$") {
        synthetic("");
        return (deliver);
    }
    if (resp.status == 200 && req.url == "/health") {
        synthetic("OK");
        return (deliver);
    }
    if (resp.status == 200 && req.method == "DELETE") {
        synthetic("PURGED");
        return (deliver);
    }
}

{'fraction_non_alphanumeric': 0.21038034865293184, 'fraction_numerical': 0.019809825673534072, 'mean_word_length': 2.4121621621621623, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6601695', 'n_tokens_mistral': 992, 'n_tokens_neox': 945, 'n_words': 182}