Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 31c741d6bee7e3d654772d472cdc8d1b80b88e26 1 parent 6503680
Peter Marschall marschap authored

Showing 1 changed file with 25 additions and 2 deletions. Show diff stats Hide diff stats

  1. +25 2 lib/LWP/Protocol/ldap.pm
27 lib/LWP/Protocol/ldap.pm
@@ -13,7 +13,7 @@ use LWP::MediaTypes ();
13 13 require LWP::Protocol;
14 14 @ISA = qw(LWP::Protocol);
15 15
16   -$VERSION = "1.20";
  16 +$VERSION = "1.21";
17 17
18 18 use strict;
19 19 eval {
@@ -68,6 +68,7 @@ sub request {
68 68
69 69 # analyse HTTP headers
70 70 if (my $accept = $request->header('Accept')) {
  71 + $format = 'dsml' if $accept =~ m!\btext/(x-)?dsml\b!;
71 72 $format = 'ldif' if $accept =~ m!\btext/(x-)?ldif\b!;
72 73 $format = 'json' if $accept =~ m!\b(?:text|application)/json\b!;
73 74 }
@@ -153,6 +154,23 @@ sub request {
153 154 $response = $self->collect_once($arg, $response, $content)
154 155 if ($method ne 'HEAD');
155 156 }
  157 + elsif ($format eq 'dsml') {
  158 + require Net::LDAP::DSML;
  159 +
  160 + open(my $fh, ">", \my $content);
  161 + my $dsml = Net::LDAP::DSML->new(output => $fh, pretty_print => 1);
  162 +
  163 + $dsml->start_dsml();
  164 + while(my $entry = $mesg->shift_entry) {
  165 + $dsml->write_entry($entry);
  166 + }
  167 + $dsml->end_dsml();
  168 + close($fh);
  169 + $response->header('Content-Type' => 'text/dsml; charset=utf-8');
  170 + $response->header('Content-Length', length($content));
  171 + $response = $self->collect_once($arg, $response, $content)
  172 + if ($method ne 'HEAD');
  173 + }
156 174 elsif ($format eq 'json') {
157 175 require JSON;
158 176
@@ -259,11 +277,16 @@ They are mapped to the LDAP L<search|Net::LDAP/search> operation,
259 277 =head3 Response format
260 278
261 279 Depending on the HTTP I<Accept> header provided by the user agent,
262   -LWP::Protocol::ldap can answer the requests in one of three different
  280 +LWP::Protocol::ldap can answer the requests in one of the following
263 281 formats:
264 282
265 283 =over 4
266 284
  285 +=item DSML
  286 +
  287 +When the HTTP I<Accept> header contains the C<text/dsml> MIME type,
  288 +the response is sent as DSMLv1.
  289 +
267 290 =item JSON
268 291
269 292 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.