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

30
Org.pm
View File

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