【问题标题】:How to extract first n characters of a string in varnish-vcl?如何在varnish-vcl中提取字符串的前n个字符?
【发布时间】:2018-06-02 09:16:39
【问题描述】:

我正在寻找一种从 VCL 中的字符串中提取前“n”个字符的方法。我在 VCL 文档中找不到像 trim(str,starting_pos) 或 substring(str,len) 这样的函数。我试过在 google 和 stackoverflow 上搜索这个,但什么也没出现,所以我在这里问。我感谢您的帮助。

【问题讨论】:

    标签: varnish varnish-vcl fastly fastly-vcl


    【解决方案1】:

    我不知道 Fastly Varnish 环境中有任何此类字符串函数可用。

    但是,我认为您可以使用正则表达式捕获组来完成相同的操作。

    set req.http.Foo = "foobar";
    
    if (req.http.Foo ~ "^(.{0,3})") {
      set resp.http.match0 = re.group.0; # this should now equal 'foo'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 2018-08-21
      • 2021-10-14
      • 1970-01-01
      相关资源
      最近更新 更多