Commit cb9122a 1 parent e5470cc commit cb9122a Copy full SHA for cb9122a
File tree 4 files changed +20
-26
lines changed
4 files changed +20
-26
lines changed Original file line number Diff line number Diff line change @@ -42,23 +42,8 @@ line and headers synchronously in the connection stream before returning an
42
42
43
43
.. _GLib.OutputStream : http://valadoc.org/#!api=gio-2.0/GLib.OutputStream
44
44
45
- .. warning ::
46
-
47
- The :doc: `response ` body must be accessed at least once during the
48
- processing to ensure that the headers are written and filters applied.
49
-
50
- Some VSGI implementations rely on stream filtering to produce proper responses
51
- (chunked or gzipped ones) and these are applied when the body is accessed for
52
- the first time.
53
-
54
- .. code :: vala
55
-
56
- new Server ("org.vsgi.App", (req, res) => {
57
- res.status = 200;
58
- res.headers.append ("Transfer-Encoding", "chunked");
59
- // chunked encoding will be applied
60
- res.body.write_all ("Hello world!".data, null);
61
- });
45
+ In case the body is not accessed, the head is written synchronously on disposal
46
+ of the :doc: `response ` object.
62
47
63
48
Asynchronous processing
64
49
-----------------------
Original file line number Diff line number Diff line change @@ -421,16 +421,9 @@ namespace Valum {
421
421
* raise a {@link Valum.Status.ClientError.METHOD_NOT_ALLOWED}, otherwise
422
422
* raise a {@link Valum.Status.ClientError.NOT_FOUND} exception.
423
423
*
424
- * The response is initialized with 'chunked' transfer encoding since
425
- * most processing are generally based on stream.
426
- *
427
424
* @since 0.1
428
425
*/
429
426
public void handle (Request req , Response res ) {
430
- // sane initialization
431
- if (req. http_version == Soup . HTTPVersion . @1_1)
432
- res. headers. set_encoding (Soup . Encoding . CHUNKED );
433
-
434
427
// initial invocation
435
428
this . invoke (req, res, () = > {
436
429
var stack = new Queue<Value ?> ();
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ namespace VSGI {
87
87
this . write_head (out bytes_written);
88
88
}
89
89
} catch (IOError err) {
90
- warning (" could not write the head in the connection stream" );
90
+ warning (" could not write the head in the connection stream: %s " , err . message );
91
91
}
92
92
93
93
return this . request. connection. output_stream;
@@ -183,5 +183,21 @@ namespace VSGI {
183
183
return this . head_written;
184
184
}
185
185
#endif
186
+
187
+ /**
188
+ * Write the head before disposing references to other objects.
189
+ */
190
+ public override void dispose () {
191
+ try {
192
+ if (! head_written) {
193
+ size_t bytes_written;
194
+ write_head (out bytes_written);
195
+ }
196
+ } catch (IOError err) {
197
+ warning (" could not write the head in the connection stream: %s " , err. message);
198
+ } finally {
199
+ base . dispose ();
200
+ }
201
+ }
186
202
}
187
203
}
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ namespace VSGI {
73
73
* Once dispatched, the {@link Response.head_written} property is
74
74
* expected to be true unless its reference still held somewhere else.
75
75
*/
76
- protected void dispatch (Request req , Response res ) ensures ( res . ref_count > 1 || res . head_written ) {
76
+ protected void dispatch (Request req , Response res ) {
77
77
_application (req, res);
78
78
}
79
79
}
You can’t perform that action at this time.
0 commit comments