On Wed, May 5, 2010 at 8:46 AM, Vasiljevic Zoran <z...@archiware.com> wrote: > > On 04.05.2010, at 18:58, Stephen Deasey wrote: > >> >> What is being buffered that you're trying to flush? > > The headers! It is just a kind-of 304-type of response or > a response containing just the headers, no data. > > In the "previous life" I used SetRequiredHeaders > and then FlushHeaders. Now I need to set each thing > per line and then call Ns_ConnWrite with NULL buffer: > > was: > > Ns_ConnSetRequiredHeaders(conn, mime, size); > result = Ns_ConnFlushHeaders(conn, 200); > > is: > > Ns_ConnSetTypeHeader(conn, mime); > Ns_ConnSetLengthHeader(conn, size); > Ns_ConnSetResponseStatus(conn, 200); > if (Ns_ConnWriteData(conn, NULL, 0, 0) != NS_OK) { > result = 0; > } else { > result = size; > } > > So the 2 liner becomes 8 liner. It is not that I really > care about that, but what I find obscure is the ConnWriteData. > Something like this would be more "readable" > > Ns_ConnSetTypeHeader(conn, mime); > Ns_ConnSetLengthHeader(conn, size); > Ns_ConnSetResponseStatus(conn, 200); > result = Ns_ConnFlush(conn); > > So the hypothetical Ns_ConnFlush would write all that it can > and return the number of bytes written. Or something like that. > Is there some other means of achieving the above that I am not > aware of?
In general: result = Ns_ConnReturnData(conn, status, data, data_length, mime_type); For responses without a body: result = Ns_ConnReturnStatus(conn, status); For 304's in particular: result = Ns_ConnReturnNotModified(conn); ...and related in nsd/returnresp.c. If there's a useful HTTP response that's missing, you should probably just add it. This example is kid of buggy: > Ns_ConnSetTypeHeader(conn, mime); > Ns_ConnSetLengthHeader(conn, size); > Ns_ConnSetResponseStatus(conn, 200); > if (Ns_ConnWriteData(conn, NULL, 0, 0) != NS_OK) { > result = 0; > } else { > result = size; > } You've converted the NS_OK/NS_ERROR response from Ns_ConnWriteData to a byte count, but that doesn't really tell you anything useful. In the NS_ERROR case, some bytes might actually have been written, but you've bashed it to zero. Setting result to size (the length header) is misleading because the number of bytes written includes the bytes of the headers, which the length header does not include. The byte count can also be inflated because of character encoding and chunked-encoding framing. It might actually be decreased because compression. What you can't do is compare bytes written to your original buffer size and determine whether your write was successful. Which is one of the reasons why FlushHeaders is depreciated. ------------------------------------------------------------------------------ _______________________________________________ naviserver-devel mailing list naviserver-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/naviserver-devel