Skip to content
Browse files

LWP/Protocol/ldap.pm: add DSML as output format

  • Loading branch information...
1 parent 6503680 commit 31c741d6bee7e3d654772d472cdc8d1b80b88e26 @marschap marschap committed Sep 16, 2012
Showing with 25 additions and 2 deletions.
  1. +25 −2 lib/LWP/Protocol/ldap.pm
View
27 lib/LWP/Protocol/ldap.pm
@@ -13,7 +13,7 @@ use LWP::MediaTypes ();
require LWP::Protocol;
@ISA = qw(LWP::Protocol);
-$VERSION = "1.20";
+$VERSION = "1.21";
use strict;
eval {
@@ -68,6 +68,7 @@ sub request {
# analyse HTTP headers
if (my $accept = $request->header('Accept')) {
+ $format = 'dsml' if $accept =~ m!\btext/(x-)?dsml\b!;
$format = 'ldif' if $accept =~ m!\btext/(x-)?ldif\b!;
$format = 'json' if $accept =~ m!\b(?:text|application)/json\b!;
}
@@ -153,6 +154,23 @@ sub request {
$response = $self->collect_once($arg, $response, $content)
if ($method ne 'HEAD');
}
+ elsif ($format eq 'dsml') {
+ require Net::LDAP::DSML;
+
+ open(my $fh, ">", \my $content);
+ my $dsml = Net::LDAP::DSML->new(output => $fh, pretty_print => 1);
+
+ $dsml->start_dsml();
+ while(my $entry = $mesg->shift_entry) {
+ $dsml->write_entry($entry);
+ }
+ $dsml->end_dsml();
+ close($fh);
+ $response->header('Content-Type' => 'text/dsml; charset=utf-8');
+ $response->header('Content-Length', length($content));
+ $response = $self->collect_once($arg, $response, $content)
+ if ($method ne 'HEAD');
+ }
elsif ($format eq 'json') {
require JSON;
@@ -259,11 +277,16 @@ They are mapped to the LDAP L<search|Net::LDAP/search> operation,
=head3 Response format
Depending on the HTTP I<Accept> header provided by the user agent,
-LWP::Protocol::ldap can answer the requests in one of three different
+LWP::Protocol::ldap can answer the requests in one of the following
formats:
=over 4
+=item DSML
+
+When the HTTP I<Accept> header contains the C<text/dsml> MIME type,
+the response is sent as DSMLv1.
+
=item JSON
When the HTTP I<Accept> header contains the C<text/json> MIME type,

0 comments on commit 31c741d

Please sign in to comment.
Something went wrong with that request. Please try again.