refactor HTTP parsing

We don't need the headers at all afterwards, but when parsing XML, they
are in the way.

The "found no matches" error is no longer needed in the future.
This commit is contained in:
Roland Hieber
2017-03-11 05:45:44 +01:00
parent 60c0a65702
commit de4031dd70

38
Org.pm
View File

@@ -197,32 +197,36 @@ Accept-Language: en_US, en\r\n);
#
# parse dict.leo.org output
#
my @line = <$conn>;
close $conn or die "Connection failed: $!\n";
$this->debug( "connection: done");
$site = join "", @line;
if ($site !~ /HTTP\/1\.(0|1) 200 OK/i) {
if ($site =~ /HTTP\/1\.(0|1) (\d+) /i) {
# got HTTP error
my $err = $2;
if ($err == 407) {
croak "proxy auth required or access denied!\n";
}
else {
if ($site =~ /Leider konnten wir zu Ihrem Suchbegriff/ ||
$site =~ /found no matches for your search/
) {
$site = "";
my $got_headers = 0;
while (<$conn>) {
if ($got_headers) {
$site .= $_;
}
elsif (/^\r?$/) {
$got_headers = 1;
}
elsif ($_ !~ /HTTP\/1\.(0|1) 200 OK/i) {
if (/HTTP\/1\.(0|1) (\d+) /i) {
# got HTTP error
my $err = $2;
if ($err == 407) {
croak "proxy auth required or access denied!\n";
close $conn;
return ();
}
else {
croak "got HTTP error $err!\n";
close $conn;
return ();
}
}
}
}
close $conn or die "Connection failed: $!\n";
$this->debug( "connection: done");
my @request = (
{
id => 2,