alex-sherwin / missing-link

Simple ant http plugin
0 stars 1 forks source link

Add support for saving header values to properties #24

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It would be welcome to have the ability to save specific header values to 
properties.

In particular, we'd like to save cookies and re-send them in subsequent 
responses; that is, to save the value(s) of the Set-Cookie: header(s) from a 
response, so we can send them in Cookie: header(s) in subsequent requests. 

See related Issue 21 for further discussion.

Original issue reported on code.google.com by aronrobe...@gmail.com on 19 Aug 2011 at 5:54

GoogleCodeExporter commented 8 years ago
This issue should likely be identified as Project-ant-http and Type-Enhancement.

Original comment by aronrobe...@gmail.com on 19 Aug 2011 at 5:58

GoogleCodeExporter commented 8 years ago
Sounds like a good idea, but I'm open to suggestions before coding anything.  
At first I thought it'd be straight foward, but as you pointed out there are 
headers which can be used > 1 time, specifically the one which you are looking 
to use.

Since Ant lacks any type of procedural concepts, it becomes difficult to work 
with this type of scenario, in fact near impossible without extra libs like 
ant-contrib I would think.

I've solved complex problems using ant-contrib in the past, like taking a 
property or a properties file and using foreach 
(http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html) to iterate over 
them.

However, I don't want to code something that will require everyone to use 
another third party library; especially since is only a problem for headers 
which can repeat.

Due to Ant's simplistic nature, I'm tempted to do something like this:

<http ...>
  <saveHeader name="Response" prop="response.prop"/>
  <saveHeader name="Set-Cookie" prop="set.cookie.prop" multivalueDelimieter="###,,###"/>
</http>

So when a header with multiple values is encountered, they would all end up  in 
a single property, delimited with the specified delimiter.  

That's about the best I can think of doing with core Ant functionality, but 
what it does it let you use something like ant-contrib foreach and split the 
multi values on the delimiter, invoking a specified target for each value

Original comment by alex.she...@gmail.com on 19 Aug 2011 at 12:29

GoogleCodeExporter commented 8 years ago

Original comment by alex.she...@gmail.com on 19 Aug 2011 at 12:51

GoogleCodeExporter commented 8 years ago
You said wanted to save Set-Cookie and re-issue it right?  It now makes sense 
that this would work:

<property name="delim" value='!!!!,,!!!!"/>

<http ...>
  <saveHeader name="Set-Cookie" prop="set.cookie" multivalueDelimeter="${delim}"/>
</http>

and re-issue:

<http ...>
  <header name="Cookie" value="${set.cookie}" multivalueDelimiter="${delim}"/>
</http>

Where the existing header node would just be enhanced to split on the delim and 
put in multiple headers if the resulting array was length > 1

Would that work for you?

Original comment by alex.she...@gmail.com on 19 Aug 2011 at 12:58

GoogleCodeExporter commented 8 years ago
On its face, this looks great!

Original comment by aronrobe...@gmail.com on 19 Aug 2011 at 1:45