K
K
KPEBETKA2014-12-30 05:39:54
Perl
KPEBETKA, 2014-12-30 05:39:54

How to make Perl LWP and Expect: 100-continue header work?

I set myself the task of writing a plugin that will upload screenshots to Yandex.Disk
I ran into a problem with uploading, namely, when I try to upload an existing screenshot, the correct response with the code 201 is returned, and when I try to upload a new screenshot, the response with the code 500 is returned
I have two options:
1. LWP doesn't work correctly with Expect: 100-continue
2. I'm formatting the query incorrectly

my $content = do { open my $fl,'<:raw',$upload_filename; local $/; <$fl>; };
my $req = HTTP::Request->new( PUT => $url, undef, Content => $content );
$req->header( "Accept" => "*/*" );
$req->header( "Authorization" => "OAuth $token" );
$req->header( "Etag" => "$md5file" );
$req->header( "Sha256" => "$sha256file" );
$req->header( "Expect" => "100-continue" );
$req->header( "Content-Type" => "application/binary" );
$req->header( "Transfer-Encoding" => "chunked" );
my $res = $ua->request($req);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KPEBETKA, 2014-12-31
@KPEBETKA

I don't need bash, I'm writing a plugin for Shutter. Accordingly, only a pearl is needed.
In principle, after studying, it turned out that if there is both data and Expect, then the entire request is sent to the server and the header with the 100th response is read only when the data has already been sent. This leads to a deadlock, because the server is waiting for an Expect response from it.
It will not work separately with sending the header either - it waits for the next one immediately after the 100th response
There are two options:
1. Write using HTTP: DAW
2. Do it via sockets, without wwwlib
The first option is simple, but there will be no OAuth - authorization
The second option is difficult for me, but I'll figure it out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question