-
-
Save anonymous/328fa943206b0565d505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/UserAgent.pm b/lib/Mojo/UserAgent.pm | |
index 3182521..62dd0c3 100644 | |
--- a/lib/Mojo/UserAgent.pm | |
+++ b/lib/Mojo/UserAgent.pm | |
@@ -4,7 +4,7 @@ use Mojo::Base 'Mojo::EventEmitter'; | |
# "Fry: Since when is the Internet about robbing people of their privacy? | |
# Bender: August 6, 1991." | |
use Mojo::IOLoop; | |
-use Mojo::Util 'monkey_patch'; | |
+use Mojo::Util qw(monkey_patch term_escape); | |
use Mojo::UserAgent::CookieJar; | |
use Mojo::UserAgent::Proxy; | |
use Mojo::UserAgent::Server; | |
@@ -279,7 +279,7 @@ sub _read { | |
return $self->_remove($id) unless my $tx = $c->{tx}; | |
# Process incoming data | |
- warn "-- Client <<< Server (@{[$tx->req->url->to_abs]})\n$chunk\n" if DEBUG; | |
+ warn term_escape "-- Client <<< Server (@{[_url($tx)]})\n$chunk\n" if DEBUG; | |
$tx->client_read($chunk); | |
if ($tx->is_finished) { $self->_finish($id) } | |
elsif ($tx->is_writing) { $self->_write($id) } | |
@@ -329,6 +329,8 @@ sub _start { | |
return $id; | |
} | |
+sub _url { shift->req->url->to_abs } | |
+ | |
sub _write { | |
my ($self, $id) = @_; | |
@@ -338,7 +340,7 @@ sub _write { | |
return if !$tx->is_writing || $c->{writing}++; | |
my $chunk = $tx->client_write; | |
delete $c->{writing}; | |
- warn "-- Client >>> Server (@{[$tx->req->url->to_abs]})\n$chunk\n" if DEBUG; | |
+ warn term_escape "-- Client >>> Server (@{[_url($tx)]})\n$chunk\n" if DEBUG; | |
my $stream = $self->_loop($c->{nb})->stream($id)->write($chunk); | |
$self->_finish($id) if $tx->is_finished; | |
diff --git a/lib/Mojo/Util.pm b/lib/Mojo/Util.pm | |
index fa4723b..94164da 100644 | |
--- a/lib/Mojo/Util.pm | |
+++ b/lib/Mojo/Util.pm | |
@@ -56,8 +56,8 @@ our @EXPORT_OK = ( | |
qw(decode deprecated dumper encode hmac_sha1_sum html_unescape md5_bytes), | |
qw(md5_sum monkey_patch punycode_decode punycode_encode quote), | |
qw(secure_compare sha1_bytes sha1_sum slurp split_header spurt squish), | |
- qw(steady_time tablify trim unindent unquote url_escape url_unescape), | |
- qw(xml_escape xor_encode xss_escape) | |
+ qw(steady_time tablify term_escape trim unindent unquote url_escape), | |
+ qw(url_unescape xml_escape xor_encode xss_escape) | |
); | |
sub b64_decode { decode_base64 $_[0] } | |
@@ -299,6 +299,12 @@ sub tablify { | |
return join '', map { sprintf "$format\n", @$_ } @$rows; | |
} | |
+sub term_escape { | |
+ my $str = shift; | |
+ $str =~ s/(\p{XPosixCntrl})/sprintf('\\x{%x}', ord($1))/ge; | |
+ return $str; | |
+} | |
+ | |
sub trim { | |
my $str = shift; | |
$str =~ s/^\s+//; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment