valum-framework / valum

Web micro-framework written in Vala
https://valum-framework.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
225 stars 23 forks source link

Split 'write_head' into 'write_status_line' and 'write_headers' #186

Closed arteymix closed 8 years ago

arteymix commented 8 years ago

Some protocols like 'HTTP/2.0' use different channels for sending headers and body resulting in the possibility of having parts of the body emitted while not all headers are sent. This is while splitting Response.write_head is very convenient.

Automatically calling a writer should be implementation-specific, so we don't write headers when the body is first accessed.

Response.head_written is replaced by a flag covering the following conditions:

It's not possible to reliably know when the body has been written.

It's handy to have a final status line but not yet headers, especially if one wants to generate headers based on a specific status.

res.wrote_status_line.connect (() => {
    // status line is final
    if (res.is_cacheable ()) {
        res.headers.append ("Cache-Control", "public");
    }
});

There's some tests to fix and probably add cover new edge cases.

codecov-io commented 8 years ago

Current coverage is 64.88%

Merging #186 into master will decrease coverage by 0.70%

@@             master       #186   diff @@
==========================================
  Files            31         31          
  Lines           988       1011    +23   
  Methods           0          0          
  Messages          0          0          
  Branches        116        114     -2   
==========================================
+ Hits            648        656     +8   
- Misses          303        318    +15   
  Partials         37         37          

Powered by Codecov. Last updated by 0191801...e50674f