--- trunk/Estraier.pm 2006/01/05 22:36:10 39 +++ trunk/Estraier.pm 2006/01/05 23:00:22 40 @@ -272,8 +272,8 @@ $draft .= "\n"; - $draft .= join("\n", @{ $self->{dtexts} }) . "\n"; - $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n"; + $draft .= join("\n", @{ $self->{dtexts} }) . "\n" if ($self->{dtexts}); + $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n" if ($self->{htexts}); return $draft; } @@ -752,14 +752,16 @@ sub set_auth { my $self = shift; my ($login,$passwd) = @_; - $self->{auth} = encode_base64( "$login:$passwd" ); + my $basic_auth = encode_base64( "$login:$passwd" ); + chomp($basic_auth); + $self->{auth} = $basic_auth; } =head2 status Return status code of last request. - print $res->status; + print $node->status; C<-1> means connection failure. @@ -770,6 +772,18 @@ return $self->{status}; } +=head2 put_doc + + $node->put_doc( $document_draft ); + +=cut + +sub put_doc { + my $self = shift; + my $doc = shift || return; + $self->shuttle_url( $self->{url} . '/put_doc', 'text/x-estraier-draft', $doc->dump_draft, undef); +} + =head2 shuttle_url This is method which uses C to communicate with Hyper Estraier node @@ -787,7 +801,7 @@ my ($url, $content_type, $reqbody, $resbody) = @_; - my $status = -1; + $self->{status} = -1; warn "## $url\n"; @@ -817,10 +831,10 @@ $headers .= "GET $query HTTP/1.0\r\n"; } - $headers .= "Host: $url->host:$url->port\r\n"; + $headers .= "Host: " . $url->host . ":" . $url->port . "\r\n"; $headers .= "Connection: close\r\n"; $headers .= "User-Agent: Search-Estraier/$Search::Estraier::VERSION\r\n"; - $headers .= "Content-Type $content_type\r\n"; + $headers .= "Content-Type: $content_type\r\n"; $headers .= "Authorization: Basic $self->{auth}\r\n"; my $len = 0; { @@ -842,14 +856,14 @@ return -1; } - warn "## headers:\n$headers\n" if ($self->{debug}); + warn $headers if ($self->{debug}); print $sock $headers or carp "can't send headers to network:\n$headers\n" and return -1; if ($reqbody) { - warn "## request body:\n$headers\n" if ($self->{debug}); - print $sock $$reqbody or + warn $reqbody if ($self->{debug}); + print $sock $reqbody or carp "can't send request body to network:\n$$reqbody\n" and return -1; } @@ -858,7 +872,7 @@ my ($schema, $res_status, undef) = split(/ */, $line, 3); return if ($schema !~ /^HTTP/ || ! $res_status); - $status = $res_status; + $self->{status} = $res_status; warn "## response status: $res_status\n" if ($self->{debug}); # skip rest of headers @@ -866,7 +880,7 @@ while ($line) { $line = <$sock>; $line =~ s/[\r\n]+$//; - warn "## ", $line || 'NULL', " ##\n"; + warn "## ", $line || 'NULL', " ##\n" if ($self->{debug}); }; # read body @@ -876,10 +890,9 @@ $$resbody .= $buf if ($resbody); } while ($len); - - warn "## response body:\n$$resbody\n" if ($self->{debug}); + warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug}); - return $status; + return $self->{status}; } ###