rejetto forum

Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: LeoNeeson on November 12, 2022, 12:52:55 AM

Title: Macros matching only a Content-Type
Post by: LeoNeeson on November 12, 2022, 12:52:55 AM
After reading this (https://rejetto.com/forum/index.php?topic=13561.0) post, I have a hypothetical question about macros. I already know how to make a macro that match a file extension in a URL (for example: {.match|*.jpg;*.gif|%url%.}), but I don't know how to ONLY match a 'Content-Type' found in a header. (I've read the Wiki (https://www.rejetto.com/wiki/index.php/HFS:_scripting_commands), but found nothing relevant to my question)

I've tried with the following, without success:

Code: [Select]
[pre-filter-request]
{.if|{.match|*text/html*|{.header|Content-Type.}.}|{:
{.add to log|Web page was served.}
{.add header|Expires: 1.}
:}.}

My idea is ONLY match requests, with any of these headers:

Content-Type:"text/html; charset=utf-8"

and/or

Content-Type:"text/html"

Do you know how to ONLY match a header, with a 'Content-Type' of 'text/html'?. I do NOT want to match files with *.html or *.htm extension (I repeat: I do NOT want to filter or match files by extension). The type of 'Content-Type' was only an example, but it can be any other type.

What am I doing wrong?... :-\
Title: Re: Macros matching only a Content-Type
Post by: LeoNeeson on November 12, 2022, 02:56:04 AM
I've also tried this (without success, since it doesn't work as expected):

Code: [Select]
[pre-filter-request]
{.add header|Expires: 0|if=
   {.and
      |{.match|*text/html*|{.header|Content-Type.}.}
   .}   
.}

Neither this works...

Code: [Select]
[pre-filter-request]
{.if|
   {.match|*html*|{.header|Content-Type.}.}|
{:
          {.add to log|Web site served 2.}
  {.add header|Expires: 2.}
:}
   .}
.}

This is puzzling, but after many crazy tests, I think we got a bug...

See, this example SEEMS to working (but it's working bad, see at the end):

Code: [Select]
[+request]
{.disconnection reason|It seems to work since all UA have Mozilla|if=
   {.and
      |{.match|*Mozilla*|{.header|User-Agent.}.}
   .}   
.}

But this another example should NOT work (since 'Content-Type' can never be 'Mozilla'):

Code: [Select]
[+request]
{.disconnection reason|Whoa there, something is wrong here|if=
   {.and
      |{.match|*Mozilla*|{.header|Content-Type.}.}
   .}   
.}

And another crazy example...

Code: [Select]
[+request]
{.disconnection reason|It should work since there is no mysterious browser|if=
   {.and
      |{.match|*mysterious*|{.header|User-Agent.}.}
   .}   
.}

ยป Result: Something weird is happening here (or I'm doing all wrong)... :o

*** Since I already know Rejetto is not actively working on v2.4x (and I don't expect him to do it), I'm open to receive the modifications needed in the source code to fix this (since I can compile HFS by myself). ***