Dancer
view release on metacpan or search on metacpan
786787788789790791792793794795796797798799800801802803804805806- If YAML does not load, Dancer::Config now reports why (Ovid)
1.3095_01 2012-06-22
[BUG FIXES]
- Don't assume returned references are blessed
when
considering
continuations (Neil Hooey, GH-778)
- Malformed/missing cookies caused warnings (James Aitken/LoonyPandora,
GH-782 and GH-783)
- Avoid potential crash in t/14_serializer/06_api.t
if
tmp dir is replaced
when
%ENV
gets cleared (Adam Kennedy)
- Properly initialize
%callbacks
to
default
empty hashref in _send_file
if
not provided (Gary Mullen)
[DOCUMENTATION]
- Update Ubic service example (Vyacheslav Matyukhin)
- Silly typo fixing (Paul Fenwick)
- Typo in Dancer::Test file upload example (Jonathan
"Duke"
Leto)
- UTF-8 fixes in POD (ambs)
[ENHANCEMENTS]
- Add UTC timestamp options
for
logger_format (Alex C - perlpong).
99899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
};
Send file supports streaming possibility using PSGI streaming. The
server should support it but normal streaming is supported on most,
if
not all.
get
'/download/:file'
=>
sub
{
send_file( params->{file},
streaming
=> 1 );
}
You can control what happens using callbacks.
First, around_content allows you to get the writer object and the chunk
of content
read
, and then decide what to
do
with
each
chunk:
get
'/download/:file'
=>
sub
{
send_file(
params->{file},
streaming
=> 1,
callbacks
=> {
around_content
=>
sub
{
my
(
$writer
,
$chunk
) =
@_
;
$writer
->
write
(
"* $chunk"
);
},
},
);
}
You can
use
around
to all get all the content (whether a filehandle
if
it
's a regular file or a full string if it'
s a
scalar
ref
) and decide
what to
do
with
it:
get
'/download/:file'
=>
sub
{
send_file(
params->{file},
streaming
=> 1,
callbacks
=> {
around
=>
sub
{
my
(
$writer
,
$content
) =
@_
;
# we know it's a text file, so we'll just stream
# line by line
while
(
my
$line
= <
$content
> ) {
$writer
->
write
(
$line
);
}
},
},
);
}
Or you could
use
override
to control the entire streaming callback
request:
get
'/download/:file'
=>
sub
{
send_file(
params->{file},
streaming
=> 1,
callbacks
=> {
override
=>
sub
{
my
(
$respond
,
$response
) =
@_
;
my
$writer
=
$respond
->( [
$newstatus
,
$newheaders
] );
$writer
->
write
(
"some line"
);
},
},
);
}
lib/Dancer.pm view on Meta::CPAN
422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468if
(
exists
(
$options
{filename})) {
$resp
->push_header(
'Content-Disposition'
=>
"attachment; filename=\"$options{filename}\""
);
}
if
(
$options
{
'streaming'
} ) {
# handle streaming
$resp
->streamed(
sub
{
my
(
$status
,
$headers
) =
@_
;
my
%callbacks
=
defined
$options
{
'callbacks'
} ?
%{
$options
{
'callbacks'
} } :
();
return
sub
{
my
$respond
=
shift
;
exists
$callbacks
{
'override'
}
and
return
$callbacks
{
'override'
}->(
$respond
,
$resp
);
# get respond callback and set headers, get writer in return
my
$writer
=
$respond
->( [
$status
,
$headers
,
] );
# get content from original response
my
$content
=
$resp
->content;
exists
$callbacks
{
'around'
}
and
return
$callbacks
{
'around'
}->(
$writer
,
$content
);
if
(
ref
$content
) {
my
$bytes
=
$options
{
'bytes'
} ||
'43008'
;
# 42K (dams)
my
$buf
;
while
( (
my
$read
=
sysread
$content
,
$buf
,
$bytes
) != 0 ) {
if
(
exists
$callbacks
{
'around_content'
} ) {
$callbacks
{
'around_content'
}->(
$writer
,
$buf
);
}
else
{
$writer
->
write
(
$buf
);
}
}
}
else
{
$writer
->
write
(
$content
);
}
};
} );
}
lib/Dancer.pm view on Meta::CPAN
149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
}
};
Send file supports streaming possibility using PSGI streaming. The server should
support it but normal streaming is supported on most,
if
not all.
get
'/download/:file'
=>
sub
{
send_file( params->{file},
streaming
=> 1 );
}
You can control what happens using callbacks.
First, C<around_content> allows you to get the writer object and the chunk of
content
read
, and then decide what to
do
with
each
chunk:
get
'/download/:file'
=>
sub
{
send_file(
params->{file},
streaming
=> 1,
callbacks
=> {
around_content
=>
sub
{
my
(
$writer
,
$chunk
) =
@_
;
$writer
->
write
(
"* $chunk"
);
},
},
);
}
a regular file or a full string
if
it's a
scalar
ref
) and decide what to
do
with
it:
get
'/download/:file'
=>
sub
{
send_file(
params->{file},
streaming
=> 1,
callbacks
=> {
around
=>
sub
{
my
(
$writer
,
$content
) =
@_
;
# we know it's a text file, so we'll just stream
# line by line
while
(
my
$line
= <
$content
> ) {
$writer
->
write
(
$line
);
}
},
},
);
}
get
'/download/:file'
=>
sub
{
send_file(
params->{file},
streaming
=> 1,
callbacks
=> {
override
=>
sub
{
my
(
$respond
,
$response
) =
@_
;
my
$writer
=
$respond
->( [
$newstatus
,
$newheaders
] );
$writer
->
write
(
"some line"
);
},
},
);
}
( run in 0.282 second using v1.01-cache-2.11-cpan-00829025b61 )