» Perl » HTTP::Response may have a different definition of success than you do

HTTP::Response may have a different definition of success than you do

This has bitten me before, so I thought it was worth writing about. This RT ticket explains it better than I can, but let me sum things up here.

Consider this code:

99 times out of 100, this will do what you mean. Occasionally it doesn't.

What is the definition of success? In this case it means that there's an HTTP response code in the 200s.

Q: What happens if you've gotten a 200 response code in the server headers but (for example) there's a problem with the response body?

A: is_success still returns true.

is_success gives you a technically correct answer, but in this case technically correct isn't always helpful because something else may have genuinely gone wrong.

Consider what happens in this case where HTML::HeadParser is not installed.

If you want to check for success with confidence, you may want to check the 'X-Died' header as well.

That seems like a lot of work, so I've proposed a workaround that will at least warn on the fact that the 'X-Died' header exists. I don't know what the right answer is, but I do know that the current behaviour is confusing.

One thought on “HTTP::Response may have a different definition of success than you do

Leave a Reply