use LWP; use URI; # Edit to your taste $BASEURL=''; # for example 'http://localhost:9080/wiml/bugzilla50773/'; die "Hey, you need to set \$BASEURL.\n" unless $BASEURL; $ua = new LWP::UserAgent; sub mkcol { my($uri) = @_; &do_req('MKCOL', $uri); } sub puttext { my($uri, $body) = @_; &do_req('PUT', $uri, [ sprintf('Content-Length: %d', length($body)) ], $body); } sub do_req { my($meth, $uri, $headers, $body) = @_; my($abs) = URI->new_abs($uri, $BASEURL); my $req = HTTP::Request->new($meth, $abs); if(defined($headers)) { foreach my $hdr (@$headers) { $hdr =~ /^(\S+):\s?(.+)$/ or die; $req->header($1 => $2); } } $req->content($body) if defined $body; print $req->as_string; { local($|) = 1; print "$meth $uri -->"; } my $resp = $ua->request($req); print " ", $resp->status_line, "\n"; unless($resp->is_success) { print $req->as_string; print $resp->as_string; die "Request failed, stopped"; } $resp; } sub acquire_lock { my($uri) = @_; $resp = &do_req('LOCK', $uri, [ 'Timeout: Second-5', 'Content-Type: application/xml' ], <<'XML'); https://issues.apache.org/bugzilla/show_bug.cgi?id=50773 XML $locktoken = $resp->header('Lock-Token'); $locktoken =~ s/^\s*\<(.+)\>\s*$/$1/; print "Lock token from response header: $locktoken\n"; $ua->default_headers->header('If', "<" . URI->new_abs($uri, $BASEURL) . "> (<$locktoken>) "); $locktoken; } &mkcol('dirA/'); &mkcol('dirB/'); &mkcol('dirA/dirA1/'); # Now acquire a lock on dirA &acquire_lock('dirA/'); &puttext('dirA/dirA1/test.txt', 'Hi, I am some text.'); print "\nWaiting for the lock we acquired to expire...\n"; sleep(7); $ua->default_headers->remove_header('If'); # This will fail with a 500 server error. &acquire_lock('dirA/');