hdr_sub模式匹配的格式

我试图匹配一个头里面有一个空格的值,而且找不到haproxy喜欢什么正则expression式。 我后面的头像是这样的:

X-Request-ID:'Foo: Bar' 

我可以确切地匹配这个头或任何以它开头的东西。 但是,我不想匹配'Foo:其他'我迄今为止的尝试:

 acl badhdr hdr_sub(X-Request-ID) -i Foo: Bar 

匹配所有以Foo开头的内容

 acl badhdr hdr_sub(X-Request-ID) -i Foo:\sBar 

根本不符合“Foo:Bar”

非常感谢

我几乎倾向于认为HAProxy接受这个事实…

 acl badhdr hdr_sub(X-Request-ID) -i Foo: Bar 

…可能是一个错误,“酒吧”正在悄然丢弃。 我必须进一步研究,以确定,但正确的方式来expression这将是一个反斜杠逃脱的空间…

 acl badhdr hdr_sub(X-Request-ID) -i Foo:\ Bar 

…或将expression式用引号引起来…

 acl badhdr hdr_sub(X-Request-ID) -i "Foo: Bar" 

请注意_sub不是正则expression式 – 它只是子string匹配。 您可能需要hdr_beg – 开始子string。

对于一个锚定的正则expression式,包括开始' (假设这是标题的一部分,因为它看起来是从这个问题,它也需要逃脱),我相信expression式是这样的:

 acl badhdr hdr_reg(X-Request-ID) -i ^\'Foo:\ Bar 

根据文档 ,hdr_sub接受子串匹配作为参数。

根据关于HTTP头部操作的文档(相同的链接),子串正则expression式有点不合常规:

 \t for a tab \r for a carriage return (CR) \n for a new line (LF) \ to mark a space and differentiate it from a delimiter \# to mark a sharp and differentiate it from a comment \\ to use a backslash in a regex \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy) \xXX to write the ASCII hex code XX as in the C language 

因此,这应该为你工作:

 acl badhdr hdr_sub(X-Request-ID) -i Foo:\ Bar