Hinnerk Altenburg

Web Developer in Hamburg, Germany

Archive for the ‘gist’ tag

WordPress filter hook: log and debug WP_Http requests

without comments

This WordPress filter hooks into WP_Http::_dispatch_request() to write all request and response details into a logfile.
It logs all HTTP requests (GET, POST, HEAD) that are sent and received by the WP_Http class, e.g. explicitly via $wp_http_object->request() or via wp_remote_request() or wp_remote_get() or wp_remote_post() or wp_remote_head().
The hook is useful for logging while debugging WordPress plugins that connect to other servers.

See also:
WordPress Plugin API Documentation: Filters
WordPress Function Reference: add_filter

Written by Hinnerk

Mai 31st, 2012 at 10:48 pm

Posted in English

Tagged with , , , , ,

Perl: Handle malformed UTF-8 strings with Encode::encode

without comments

Having the error message “Malformed UTF-8 character (fatal)” in my log files, I tried to handle this properly without letting the process die nor throwing away the whole string.
Having some research on Google I came up with following solution:

See also:
http://perldoc.perl.org/Encode.html#Handling-Malformed-Data
http://www.perlmonks.org/?node_id=839519

Written by Hinnerk

August 31st, 2011 at 4:58 pm

Posted in English

Tagged with , , , , ,

Set a custom HTTP User-Agent in Perl with WWW::Mechanize

with 2 comments

This is how you can dynamically set a custom HTTP User-Agent for your Perl requests to fake a device or browser for testing purpose or getting a device-specific version of a website.
WWW::Mechanize supports setting a custom user-agent with the constructor and after this gives a choice of 6 pre-defined basic user-agents ( $mech->agent_alias() ), only.

The following code demonstrates how to dynamically change the user-agent on a Mechanize object.

Written by Hinnerk

Juni 29th, 2011 at 9:21 pm

Posted in English

Tagged with , , , , ,