Skip to content

Commit

Permalink
Introduce BufferedResponse filter
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Aug 24, 2015
1 parent f5d7595 commit 3725aa0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/app/app.vala
Expand Up @@ -334,7 +334,7 @@ app.matcher (VSGI.Request.GET, (req) => { return req.uri.get_path () == "/custom
});

app.get ("filtering", (req, res, next) => {
next (req, new BufferedResponse (res));
next (req, new VSGI.BufferedResponse (res));
}).then ((req, res) => {
// res is now buffered
res.body.write_all ("Hello world!".data, null);
Expand Down
21 changes: 21 additions & 0 deletions src/vsgi-buffered-response.vala
@@ -0,0 +1,21 @@
using GLib;

namespace VSGI {

public class BufferedResponse : ResponseFilter {

private BufferedOutputStream? buffer = null;

public override OutputStream body {
get {
if (this.buffer == null)
this.buffer = new BufferedOutputStream (base_response.body);
return this.buffer;
}
}

public BufferedResponse (Response base_response) {
Object (base_response: base_response);
}
}
}

0 comments on commit 3725aa0

Please sign in to comment.