]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/perl/lib/Thrift/HttpClient.pm
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
28 use Thrift
::Exception
;
29 use Thrift
::Transport
;
31 package Thrift
::HttpClient
;
32 use base
('Thrift::Transport');
33 use version
0.77; our $VERSION = version-
>declare("$Thrift::VERSION");
37 my $classname = shift;
38 my $url = shift || 'http://localhost:9090';
40 my $out = IO
::String-
>new;
51 return bless($self,$classname);
59 $self->{timeout
} = $timeout;
64 warn 'setRecvTimeout is deprecated - use setTimeout instead';
65 # note: recvTimeout was never used so we do not need to do anything here
73 warn 'setSendTimeout is deprecated - use setTimeout instead';
75 $self->setTimeout($timeout);
81 my ($name, $value) = @_;
83 $self->{headers
}->{$name} = $value;
87 # Tests whether this is open
89 # @return bool true if the socket is open
99 # Cleans up the buffer.
104 if (defined($self->{io
})) {
111 # Guarantees that the full amount of data is read.
113 # @return string The data, of exact length
114 # @throws TTransportException if cannot read data
121 my $buf = $self->read($len);
123 if (!defined($buf)) {
124 die Thrift
::TTransportException-
>new("TSocket: Could not read $len bytes from input buffer",
125 Thrift
::TTransportException
::END_OF_FILE
);
131 # Read and return string
140 my $in = $self->{in};
143 die Thrift
::TTransportException-
>new('Response buffer is empty, no request.',
144 Thrift
::TTransportException
::END_OF_FILE
);
147 my $ret = sysread($in, $buf, $len);
148 if (! defined($ret)) {
149 die Thrift
::TTransportException-
>new('No more data available.',
150 Thrift
::TTransportException
::TIMED_OUT
);
154 die Thrift
::TTransportException-
>new("$@", Thrift
::TTransportException
::UNKNOWN
);
167 $self->{out
}->print($buf);
171 # Flush output (do the actual HTTP/HTTPS request)
177 my $ua = LWP
::UserAgent-
>new(
178 'timeout' => ($self->{timeout
} / 1000),
179 'agent' => 'Perl/THttpClient'
181 $ua->default_header('Accept' => 'application/x-thrift');
182 $ua->default_header('Content-Type' => 'application/x-thrift');
183 $ua->cookie_jar({}); # hash to remember cookies between redirects
185 my $out = $self->{out
};
186 $out->setpos(0); # rewind
187 my $buf = join('', <$out>);
189 my $request = HTTP
::Request-
>new(POST
=> $self->{url
}, ($self->{headers
} || undef), $buf);
190 my $response = $ua->request($request);
191 my $content_ref = $response->content_ref;
193 my $in = IO
::String-
>new($content_ref);
196 $in->setpos(0); # rewind
199 $out = IO
::String-
>new;