Re: http_get does not retrieve page content
- Posted by DerekParnell (admin) Jan 09, 2013
- 1340 views
I think that 'trim()' is a better way to go as that would be more tolerant of the variations that might exist in web servers out in the wild.
Is there any evidence to suggest that such servers do exist? I would be interested in seeing one.
I have none.
But let's assume that they don't; in other words, every web server that currently exists and will ever exist will always deliver correct webpage headers. In that case, trim() does no harm and runs very quickly (has almost nothing to do).
Now let's continue hypothesising ... what if, a web sever actually does exist that can deliver headers that have non-standard whitespace. We need to ask ourselves, do we care? ... does the user of our application care? Probably not. So if the library uses trim(), it will be as if standard headers were used and the application doesn't trip over or do something unintended.
So on the balance of probability (there exists a chance of bad web servers existing), and in the interests of using defensive programming, why not use trim() regardless.