mirror of
https://codeberg.org/scip/leo.git
synced 2025-12-16 12:11:04 +01:00
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:
38
Org.pm
38
Org.pm
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user