Do you know where your variables are? | |
PerlMonks |
[Solved] Testing Dancer2 - simulating requests from different IP addressesby davies (Prior) |
on Apr 09, 2016 at 13:48 UTC ( [id://1160000]=perlquestion: print w/replies, xml ) | Need Help?? |
davies has asked for the wisdom of the Perl Monks concerning the following question: I am writing a web app that is intended to give different responses depending on the IP address that originates the request. I can't find any documentation on how to do this. The Dancer2 documentation suggests using Plack::Test. This indicates that simulating IP addresses should be possible: For your convenience, the HTTP::Request given to the callback automatically uses the HTTP protocol and the localhost (127.0.0.1 by default)Unfortunately, I cannot find anything in the HTTP::Request documentation to indicate how to change this default. The sort of code I have in my test file is taken from the Dancer2 docs:
I am able to work with the response perfectly happily and get passing tests. What I can't do is test the different responses to different IP addresses that I want to achieve. Any pointers would be greatly appreciated. Regards, John Davies Update: I tried $ENV{REMOTE_ADDR} = '127.0.0.254';, which had no effect. Update 2: Adam Taylor of Adzuna isn't a monk but emailed me a solution involving monkey patching. He has posted it at https://gist.github.com/adamtaylor/68a6a2c9a7e468895815c6ef718fcc0a. It works perfectly for me.
Back to
Seekers of Perl Wisdom
|
|