RewriteHeader change method of the client request

Topics: User Forum
May 3, 2010 at 10:34 PM
Edited May 3, 2010 at 10:35 PM

I want to change the method of the client request (from HEAD to GET). I have the following lines:

RewriteCond %{HTTP_METHOD} HEAD
RewriteRule (.*) $1/requestheader=HEAD
RewriteHeader METHOD HEAD GET

The first to lines are working fine, but I don't  get the third to work. Does anyone know the correct syntax for the third line?

TIA,

Stephan

Coordinator
May 4, 2010 at 3:40 AM

As far as I know, you can't change the method on an HTTP Request, once the request has arrived at the server.

It seems to me it would be a violation of the HTTP Protocol.

What are you *really* trying to do?

 

 

May 4, 2010 at 11:06 AM
It is possible. In the isapi rewrite filter of Helicon Tech this is explicitly explained:

This last example will direct all WebDAV requests to the /webdav.asp script by changing request method:

RewriteCond METHOD OPTIONS
RewriteRule (.*) /webdav.asp?$1
RewriteHeader METHOD OPTIONS GET

I need to do it because the isapi I use (foxisapi) does not support a HEAD request. A HEAD request is the same as a GET request, but only the header is sent back.
I have to deal with the HEAD request. That leaves me with two options: use another isapi or change the request from HEAD to GET and sent back only the header.
I was hoping it is possible with the Ionics rewrite filter too.

Op 4-5-2010 4:40, Cheeso schreef:

From: Cheeso

As far as I know, you can't change the method on an HTTP Request, once the request has arrived at the server.

It seems to me it would be a violation of the HTTP Protocol.

What are you *really* trying to do?

 

 

Coordinator
May 4, 2010 at 2:22 PM

what does the IIRF log file say? 

It seems to me that given the order of rules you use, the METHOD will be HEAD forever.  Each time through the list of rules, IIRF will encounter the condition testing the METHOD.  It will then rewrite the URL to a different value. Then it will cycle, and re-evaluate all the rules.   Repeat from the beginning. Eventually IIRF will reach the IterationLimit and will bail out.  Your RewriteHeader will never fire.

You need to change the order of those two rules, and add a condition.  Like this:

RewriteCond %{URL} requestheader=HEAD
RewriteHeader METHOD HEAD GET

RewriteCond %{HTTP_METHOD} HEAD
RewriteRule (.*) $1/requestheader=HEAD

That takes care of the logic flow.  I still don't know if it will work, though, in practice. I never tried it.

 

May 4, 2010 at 10:31 PM
Thank for thinking with me. To go back to the root of the problem, I simplified the rules (and for testing it is easier to change GET into HEAD.
The rules are:

RewriteCond %{HTTP_METHOD} GET
RewriteHeader METHOD GET HEAD

RewriteRule  ^/$                /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/
RewriteRule  ^/([^.\?]+)$          /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1
RewriteRule  ^/([^.\?]+).html$  /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1.html
RewriteRule  ^/([^.\?]+).shtml$  /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1.shtml
RewriteRule  ^/exit/(.*)$        /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/exit/$1
RewriteRule  ^/scripts/foxisapi.dll/([^.\?]+)$        /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?$1

The last six work properly. The relevant part in the logfile is:

1 -  4068 - ReadSiteConfig: line  49: MaxMatchCount 10
2 -  4068 - ReadSiteConfig: line  50: RewriteCond   %{HTTP_METHOD}  GET
3 -  4068 - ReadSiteConfig: line  51: RewriteHeader (rule 1)  'METHOD'  'GET'  'HEAD'   (null)
4 -  4068 - ReadSiteConfig: not a duplicate rule...
5 -  4068 - ReadSiteConfig: line  53: RewriteRule (rule 2)  '^/$'  '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/'   (null)
6 -  4068 - ReadSiteConfig: not a duplicate rule...
7 -  4068 - ReadSiteConfig: line  54: RewriteRule (rule 3)  '^/([^.\?]+)$'  '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1'   (null)
8 -  4068 - ReadSiteConfig: not a duplicate rule...
9 -  4068 - ReadSiteConfig: line  55: RewriteRule (rule 4)  '^/([^.\?]+).html$'  '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1.html'   (null)
10 -  4068 - ReadSiteConfig: not a duplicate rule...
11 -  4068 - ReadSiteConfig: line  56: RewriteRule (rule 5)  '^/([^.\?]+).shtml$'  '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1.shtml'   (null)
12 -  4068 - ReadSiteConfig: not a duplicate rule...
13 -  4068 - ReadSiteConfig: line  57: RewriteRule (rule 6)  '^/exit/(.*)$'  '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/exit/$1'   (null)
14 -  4068 - ReadSiteConfig: not a duplicate rule...
15 -  4068 - ReadSiteConfig: line  58: RewriteRule (rule 7)  '^/scripts/foxisapi.dll/([^.\?]+)$'  '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?$1'   (null)
16 -  4068 - ReadSiteConfig: not a duplicate rule...
17 -  4068 - ReadSiteConfig: line  64: IterationLimit 8
18 -  4068 - ReadSiteConfig: Done reading, found 7 rules (0 errors, 0 warnings) on 196 lines
19 -  4068 - ReleaseOrExpireSiteConfig: site '/LM/W3SVC/1488609430/Root' (era=4) (rc=0) (Expired=1) (ptr=0x01CC4308)...
20 -  4068 - GetSiteConfig: Obtain  site '/LM/W3SVC/1488609430/Root' (era=5) (rc=1) (Expired=0) (ptr=0x01CC4818)...
21 -  4068 - HttpFilterProc: SF_NOTIFY_URL_MAP
22 -  4068 - HttpFilterProc: cfg= 0x01CC4818
23 -  4068 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
24 -  4068 - DoRewrites
25 -  4068 - GetServerVariable_AutoFree: getting 'url'
26 -  4068 - GetServerVariable_AutoFree: 128 bytes
27 -  4068 - GetServerVariable_AutoFree: result ''
28 -  4068 - GetHeader_AutoFree: getting 'url'
29 -  4068 - GetHeader_AutoFree: 54 bytes   ptr:0x000FDD28
30 -  4068 - GetHeader_AutoFree: 'url' = '/vacatures/medewerker-distributiedienst/showvac/95977'
31 -  4068 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
32 -  4068 - GetServerVariable_AutoFree: 1 bytes
33 -  4068 - GetServerVariable_AutoFree: result ''
34 -  4068 - GetHeader_AutoFree: getting 'method'
35 -  4068 - GetHeader_AutoFree: 4 bytes   ptr:0x000FDE38
36 -  4068 - GetHeader_AutoFree: 'method' = 'GET'
37 -  4068 - DoRewrites: New Url, before decoding: '/vacatures/medewerker-distributiedienst/showvac/95977'
38 -  4068 - DoRewrites: Url (no decoding): '/vacatures/medewerker-distributiedienst/showvac/95977'
39 -  4068 - EvaluateRules: depth=0
40 -  4068 - GetHeader_AutoFree: getting 'METHOD:'
41 -  4068 - GetHeader_AutoFree: 128 bytes   ptr:0x000FDEC0
42 -  4068 - GetHeader_AutoFree: 'METHOD:' = ''
43 -  4068 - EvaluateRules: Rule 1 : -1 (No match)
44 -  4068 - EvaluateRules: Rule 2 : -1 (No match)
45 -  4068 - EvaluateRules: Rule 3 : 2 matches
46 -  4068 - ReplaceServerVariables: in='/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1' out='/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1'
47 -  4068 - GenerateReplacementString: result '/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/vacatures/medewerker-distributiedienst/showvac/95977'
48 -  4068 - EvaluateRules: Result (length 104): /scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/vacatures/medewerker-distributiedienst/showvac/95977

I think line 40 shows the problem. The semicolon should not be there...

Stephan

From: Cheeso

what does the IIRF log file say? 

It seems to me that given the order of rules you use, the METHOD will be HEAD forever.  Each time through the list of rules, IIRF will encounter the condition testing the METHOD.  It will then rewrite the URL to a different value. Then it will cycle, and re-evaluate all the rules.   Repeat from the beginning. Eventually IIRF will reach the IterationLimit and will bail out.  Your RewriteHeader will never fire.

You need to change the order of those two rules, and add a condition.  Like this:

RewriteCond %{URL} requestheader=HEAD
RewriteHeader METHOD HEAD GET

RewriteCond %{HTTP_METHOD} HEAD
RewriteRule (.*) $1/requestheader=HEAD

  

That takes care of the logic flow.  I still don't know if it will work, though, in practice. I never tried it.

 



Geen virus gevonden in het binnenkomende-bericht.
Gecontroleerd door AVG - www.avg.com 
Versie: 9.0.814 / Virusdatabase: 271.1.1/2851 - datum van uitgifte: 05/03/10 08:27:00

  
Coordinator
May 5, 2010 at 12:53 AM

yes, I think you might be right about that!

 

Coordinator
May 5, 2010 at 1:14 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
May 5, 2010 at 1:19 AM

Stephan, try the DLL attached to the workitem.  I patched it to not append the colon when the header is "method" or "url".

May 5, 2010 at 3:22 PM
Great! It is now possible to change the request method!

However, now I put back the part wich appends 'requestheader=HEAD' to
the url.
But for some reason the condition RewriteCond %{URL} requestheader=HEAD
now only works with the original url?
The logfile shows: lines 83-88, the HEAD condition is true, the url is
appended.
Lines 99 - 114: the original URL is tested against the occurance of
'requestheader=HEAD', no match. Therefore everything is repeated and the
url is appended again.

Stephan

001 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(18): RewriteCond
%{URL} requestheader=HEAD '(null)'
002 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(20): RewriteHeader
(rule 1) 'METHOD' 'HEAD' 'GET' (null)
003 - ReadVdirConfig: not a duplicate rule...
004 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(23): RewriteCond
%{HTTP_METHOD} HEAD '(null)'
005 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(24): RewriteRule
(rule 2) '(.*)' '$1/requestheader=HEAD' (null)
006 - ReadVdirConfig: not a duplicate rule...
007 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(26): RewriteRule
(rule 3) '^/$'
'/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/' (null)
008 - ReadVdirConfig: not a duplicate rule...
009 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(27): RewriteRule
(rule 4) '^/([^.\?]+)$'
'/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1' (null)
010 - ReadVdirConfig: not a duplicate rule...
011 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(28): RewriteRule
(rule 5) '^/([^.\?]+).html$'
'/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1.html' (null)
012 - ReadVdirConfig: not a duplicate rule...
013 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(29): RewriteRule
(rule 6) '^/([^.\?]+).shtml$'
'/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/$1.shtml' (null)
014 - ReadVdirConfig: not a duplicate rule...
015 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(30): RewriteRule
(rule 7) '^/exit/(.*)$'
'/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?/exit/$1' (null)
016 - ReadVdirConfig: not a duplicate rule...
017 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(31): RewriteRule
(rule 8) '^/scripts/foxisapi.dll/([^.\?]+)$'
'/scripts/foxisapi.dll/carejobs.carejobs.htmlentree?$1' (null)
018 - ReadVdirConfig: not a duplicate rule...
019 - ReadVdirConfig: D:\Carejobs\Website\Iirf.ini(37): IterationLimit 8
020 - ReadVdirConfig: Done reading INI for vdir(), found 8 rules (0
errors, 1 warnings) on 38 lines
021 - ReleaseOrExpireVdirConfig: vdir '/LM/W3SVC/1488609430/Root'
(era=10) (rc=0) (Expired=1) (ptr=0x01D021A0)...
022 - GetVdirConfig: Obtain vdir '/LM/W3SVC/1488609430/Root' (era=11)
(rc=1) (Expired=0) (ptr=0x01D04F08)...
023 - HttpFilterProc: SF_NOTIFY_URL_MAP
024 - HttpFilterProc: cfg= 0x01D04F08
025 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
026 - DoRewrites
027 - GetServerVariable_AutoFree: getting 'url'
028 - GetServerVariable_AutoFree: 128 bytes
029 - GetServerVariable_AutoFree: result ''
030 - GetHeader_AutoFree: getting 'url'
031 - GetHeader_AutoFree: 38 bytes ptr:0x001082A8
032 - GetHeader_AutoFree: 'url' = '/vacatures/vroedvrouwen/showvac/95988'
033 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
034 - GetServerVariable_AutoFree: 1 bytes
035 - GetServerVariable_AutoFree: result ''
036 - GetHeader_AutoFree: getting 'method'
037 - GetHeader_AutoFree: 5 bytes ptr:0x001083E0
038 - GetHeader_AutoFree: 'method' = 'HEAD'
039 - DoRewrites: New Url, before decoding:
'/vacatures/vroedvrouwen/showvac/95988'
040 - DoRewrites: Url (no decoding):
'/vacatures/vroedvrouwen/showvac/95988'
041 - EvaluateRules: depth=0
042 - GetServerVariable: getting 'SCRIPT_NAME'
043 - GetServerVariable: 38 bytes
044 - GetServerVariable: result '/vacatures/vroedvrouwen/showvac/95988'
045 - GetHeader_AutoFree: getting 'METHOD'
046 - GetHeader_AutoFree: 5 bytes ptr:0x00108490
047 - GetHeader_AutoFree: 'METHOD' = 'HEAD'
048 - EvaluateRules: Rule 1: pattern: HEAD subject: HEAD
049 - EvaluateRules: Rule 1 : 1 matches
050 - GetServerVariable: getting 'URL'
051 - GetServerVariable: 38 bytes
052 - GetServerVariable: result '/vacatures/vroedvrouwen/showvac/95988'
053 - ReplaceServerVariables: alloc 42 bytes
054 - GetServerVariable: getting 'URL'
055 - GetServerVariable: 38 bytes
056 - GetServerVariable: result '/vacatures/vroedvrouwen/showvac/95988'
057 - ReplaceServerVariables: variableName(URL)
value(/vacatures/vroedvrouwen/showvac/95988)
058 - ReplaceServerVariables: in='%{URL}'
out='/vacatures/vroedvrouwen/showvac/95988'
059 - EvalCondition: ts1 '/vacatures/vroedvrouwen/showvac/95988'
060 - GenerateReplacementString: alloc 45 bytes
061 - GenerateReplacementString: result
'/vacatures/vroedvrouwen/showvac/95988'
062 - EvalCondition: t(/vacatures/vroedvrouwen/showvac/95988) op(|)
p(requestheader=HEAD)
063 - EvalCondition: match result: -1 (No match)
064 - EvalCondition: Cond t(%{URL}) op(|) p(requestheader=HEAD) => FALSE
065 - EvalConditionList: rule 1, FALSE, Rule does not apply
066 - EvaluateRules: no RewriteBase
067 - EvaluateRules: Rule 2: pattern: (.*) subject:
/vacatures/vroedvrouwen/showvac/95988
068 - EvaluateRules: Rule 2 : 2 matches
069 - GetServerVariable: getting 'HTTP_METHOD'
070 - GetServerVariable: 5 bytes
071 - GetServerVariable: result 'HEAD'
072 - ReplaceServerVariables: alloc 17 bytes
073 - GetServerVariable: getting 'HTTP_METHOD'
074 - GetServerVariable: 5 bytes
075 - GetServerVariable: result 'HEAD'
076 - ReplaceServerVariables: variableName(HTTP_METHOD) value(HEAD)
077 - ReplaceServerVariables: in='%{HTTP_METHOD}' out='HEAD'
078 - EvalCondition: ts1 'HEAD'
079 - GenerateReplacementString: alloc 12 bytes
080 - GenerateReplacementString: result 'HEAD'
081 - EvalCondition: t(HEAD) op(|) p(HEAD)
082 - EvalCondition: match result: 1 (match)
083 - EvalCondition: Cond t(%{HTTP_METHOD}) op(|) p(HEAD) => TRUE
084 - EvalConditionList: rule 2, TRUE, Rule will apply
085 - ReplaceServerVariables: alloc 22 bytes
086 - ReplaceServerVariables: in='$1/requestheader=HEAD'
out='$1/requestheader=HEAD'
087 - GenerateReplacementString: alloc 64 bytes
088 - GenerateReplacementString: result
'/vacatures/vroedvrouwen/showvac/95988/requestheader=HEAD'
089 - EvaluateRules: Result (length 56):
/vacatures/vroedvrouwen/showvac/95988/requestheader=HEAD
090 - EvaluateRules: depth=1
091 - GetServerVariable: getting 'SCRIPT_NAME'
092 - GetServerVariable: 38 bytes
093 - GetServerVariable: result '/vacatures/vroedvrouwen/showvac/95988'
094 - GetHeader_AutoFree: getting 'METHOD'
095 - GetHeader_AutoFree: 5 bytes ptr:0x00108518
096 - GetHeader_AutoFree: 'METHOD' = 'HEAD'
097 - EvaluateRules: Rule 1: pattern: HEAD subject: HEAD
098 - EvaluateRules: Rule 1 : 1 matches
099 - GetServerVariable: getting 'URL'
100 - GetServerVariable: 38 bytes
101 - GetServerVariable: result '/vacatures/vroedvrouwen/showvac/95988'
102 - ReplaceServerVariables: alloc 42 bytes
103 - GetServerVariable: getting 'URL'
104 - GetServerVariable: 38 bytes
105 - GetServerVariable: result '/vacatures/vroedvrouwen/showvac/95988'
106 - ReplaceServerVariables: variableName(URL)
value(/vacatures/vroedvrouwen/showvac/95988)
107 - ReplaceServerVariables: in='%{URL}'
out='/vacatures/vroedvrouwen/showvac/95988'
108 - EvalCondition: ts1 '/vacatures/vroedvrouwen/showvac/95988'
109 - GenerateReplacementString: alloc 45 bytes
110 - GenerateReplacementString: result
'/vacatures/vroedvrouwen/showvac/95988'
111 - EvalCondition: t(/vacatures/vroedvrouwen/showvac/95988) op(|)
p(requestheader=HEAD)
112 - EvalCondition: match result: -1 (No match)
113 - EvalCondition: Cond t(%{URL}) op(|) p(requestheader=HEAD) => FALSE
114 - EvalConditionList: rule 1, FALSE, Rule does not apply
115 - EvaluateRules: no RewriteBase
116 - EvaluateRules: Rule 2: pattern: (.*) subject:
/vacatures/vroedvrouwen/showvac/95988/requestheader=HEAD
117 - EvaluateRules: Rule 2 : 2 matches
118 - GetServerVariable: getting 'HTTP_METHOD'
119 - GetServerVariable: 5 bytes
120 - GetServerVariable: result 'HEAD'
121 - ReplaceServerVariables: alloc 17 bytes
122 - GetServerVariable: getting 'HTTP_METHOD'
123 - GetServerVariable: 5 bytes
124 - GetServerVariable: result 'HEAD'
125 - ReplaceServerVariables: variableName(HTTP_METHOD) value(HEAD)
126 - ReplaceServerVariables: in='%{HTTP_METHOD}' out='HEAD'
127 - EvalCondition: ts1 'HEAD'
128 - GenerateReplacementString: alloc 12 bytes
129 - GenerateReplacementString: result 'HEAD'
130 - EvalCondition: t(HEAD) op(|) p(HEAD)
131 - EvalCondition: match result: 1 (match)
132 - EvalCondition: Cond t(%{HTTP_METHOD}) op(|) p(HEAD) => TRUE
133 - EvalConditionList: rule 2, TRUE, Rule will apply
134 - ReplaceServerVariables: alloc 22 bytes
135 - ReplaceServerVariables: in='$1/requestheader=HEAD'
out='$1/requestheader=HEAD'
136 - GenerateReplacementString: alloc 83 bytes
137 - GenerateReplacementString: result
'/vacatures/vroedvrouwen/showvac/95988/requestheader=HEAD/requestheader=HEAD'
138 - EvaluateRules: Result (length 75):
/vacatures/vroedvrouwen/showvac/95988/requestheader=HEAD/requestheader=HEAD
Coordinator
May 5, 2010 at 7:16 PM

yes, you're right.

let me look.

Coordinator
May 5, 2010 at 7:17 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
May 5, 2010 at 7:22 PM

ok, Stephan, please try another updated IIRF dll, available at http://iirf.codeplex.com/WorkItem/View.aspx?WorkItemId=26976 

Let me know if that works for you.

Thanks.