From: Vlad S. <ser...@us...> - 2005-07-12 03:16:15
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18700/nsd Modified Files: conn.c connio.c return.c Log Message: see ChangeLog Index: return.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/return.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** return.c 10 Jul 2005 07:27:13 -0000 1.12 --- return.c 12 Jul 2005 03:16:05 -0000 1.13 *************** *** 207,211 **** connPtr->responseStatus == 206 || connPtr->responseStatus == 304)) { ! conn->flags &= ~NS_CONN_CHUNKED; Ns_SetIDeleteKey(conn->outputheaders, "Transfer-encoding"); } --- 207,211 ---- connPtr->responseStatus == 206 || connPtr->responseStatus == 304)) { ! conn->flags &= ~NS_CONN_WRITE_CHUNKED; Ns_SetIDeleteKey(conn->outputheaders, "Transfer-encoding"); } *************** *** 215,219 **** */ ! if (conn->flags & NS_CONN_CHUNKED) { Ns_ConnCondSetHeaders(conn, "Transfer-encoding", "chunked"); Ns_SetIDeleteKey(conn->outputheaders, "Content-length"); --- 215,219 ---- */ ! if (conn->flags & NS_CONN_WRITE_CHUNKED) { Ns_ConnCondSetHeaders(conn, "Transfer-encoding", "chunked"); Ns_SetIDeleteKey(conn->outputheaders, "Content-length"); *************** *** 222,226 **** Ns_DStringPrintf(dsPtr, "HTTP/%s %d %s\r\n", ! (conn->flags & NS_CONN_CHUNKED) ? "1.1" : "1.0", connPtr->responseStatus, reason); --- 222,226 ---- Ns_DStringPrintf(dsPtr, "HTTP/%s %d %s\r\n", ! (conn->flags & NS_CONN_WRITE_CHUNKED) ? "1.1" : "1.0", connPtr->responseStatus, reason); *************** *** 254,258 **** (((connPtr->responseStatus >= 200 && connPtr->responseStatus < 300) && ((lengthHdr != NULL && connPtr->responseLength == length) || ! (conn->flags & NS_CONN_CHUNKED)) ) || (connPtr->responseStatus == 304 || connPtr->responseStatus == 201 || --- 254,258 ---- (((connPtr->responseStatus >= 200 && connPtr->responseStatus < 300) && ((lengthHdr != NULL && connPtr->responseLength == length) || ! (conn->flags & NS_CONN_WRITE_CHUNKED)) ) || (connPtr->responseStatus == 304 || connPtr->responseStatus == 201 || *************** *** 824,838 **** result = Ns_WriteConn(conn, data, len); if (result == NS_OK) { - - /* - * In chunked mode we must send the last chunk with zero size - */ - - if (len > 0 && (conn->flags & NS_CONN_CHUNKED)) { - result = Ns_WriteConn(conn, 0, 0); - } - } - - if (result == NS_OK) { result = Ns_ConnClose(conn); } --- 824,827 ---- Index: connio.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/connio.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** connio.c 10 Jul 2005 07:27:13 -0000 1.6 --- connio.c 12 Jul 2005 03:16:05 -0000 1.7 *************** *** 96,100 **** --- 96,113 ---- if (connPtr->sockPtr != NULL) { + keep = (conn->flags & NS_CONN_KEEPALIVE) ? 1 : 0; + + /* + * In chunked mode we must send the last chunk with zero size + */ + + if ((conn->flags & NS_CONN_WRITE_CHUNKED) && + !(conn->flags & NS_CONN_SENT_LAST_CHUNK)) { + if (Ns_WriteConn(conn, 0, 0) != NS_OK) { + keep = 0; + } + } + NsSockClose(connPtr->sockPtr, keep); connPtr->sockPtr = NULL; *************** *** 232,236 **** struct iovec buf[3]; ! if (!(conn->flags & NS_CONN_CHUNKED)) { buf[0].iov_base = vbuf; --- 245,249 ---- struct iovec buf[3]; ! if (!(conn->flags & NS_CONN_WRITE_CHUNKED)) { buf[0].iov_base = vbuf; *************** *** 260,263 **** --- 273,285 ---- nsend = towrite; } + + /* + * We should mark when zero length buffer was sent because it will be + * considered as last chunk + */ + + if (towrite == 0 && (conn->flags & NS_CONN_WRITE_CHUNKED)) { + conn->flags |= NS_CONN_SENT_LAST_CHUNK; + } return nsend; } *************** *** 798,807 **** static int ! ConnSend(Ns_Conn *conn, int tosend, Tcl_Channel chan, FILE *fp, int fd) { ! int nsend, toread, nread, status; char buf[IOBUFSZ]; ! ! nsend = tosend; status = NS_OK; while (status == NS_OK && nsend > 0) { --- 820,836 ---- static int ! ConnSend(Ns_Conn *conn, int nsend, Tcl_Channel chan, FILE *fp, int fd) { ! int toread, nread, status; char buf[IOBUFSZ]; ! ! /* ! * Even if nsend is 0, ensure all queued data (like HTTP response ! * headers) get flushed. ! */ ! if (nsend == 0) { ! Ns_WriteConn(conn, NULL, 0); ! } ! status = NS_OK; while (status == NS_OK && nsend > 0) { *************** *** 810,841 **** toread = sizeof(buf); } ! if (chan != NULL) { ! nread = Tcl_Read(chan, buf, toread); ! } else if (fp != NULL) { nread = fread(buf, 1, (size_t)toread, fp); if (ferror(fp)) { ! nread = -1; ! } ! } else { ! nread = read(fd, buf, (size_t)toread); ! } ! if (nread == -1) { ! status = NS_ERROR; ! } else if (nread == 0) { ! nsend = 0; /* NB: Silently ignore a truncated file. */ ! } else if ((status = Ns_WriteConn(conn, buf, nread)) == NS_OK) { nsend -= nread; ! } } - /* - * Even if nsend is 0, ensure all queued data (like HTTP response - * headers) get flushed. - * In chunked mode we must send the last chunk with zero size - */ - - if (tosend == 0 || (conn->flags & NS_CONN_CHUNKED)) { - Ns_WriteConn(conn, 0, 0); - } return status; } --- 839,861 ---- toread = sizeof(buf); } ! if (chan != NULL) { ! nread = Tcl_Read(chan, buf, toread); ! } else if (fp != NULL) { nread = fread(buf, 1, (size_t)toread, fp); if (ferror(fp)) { ! nread = -1; ! } ! } else { ! nread = read(fd, buf, (size_t)toread); ! } ! if (nread == -1) { ! status = NS_ERROR; ! } else if (nread == 0) { ! nsend = 0; /* NB: Silently ignore a truncated file. */ ! } else if ((status = Ns_WriteConn(conn, buf, nread)) == NS_OK) { nsend -= nread; ! } } return status; } Index: conn.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/conn.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** conn.c 10 Jul 2005 07:27:13 -0000 1.19 --- conn.c 12 Jul 2005 03:16:05 -0000 1.20 *************** *** 887,891 **** Ns_ConnGetChunkedFlag(Ns_Conn *conn) { ! return (conn->flags & NS_CONN_CHUNKED) ? NS_TRUE : NS_FALSE; } --- 887,891 ---- Ns_ConnGetChunkedFlag(Ns_Conn *conn) { ! return (conn->flags & NS_CONN_WRITE_CHUNKED) ? NS_TRUE : NS_FALSE; } *************** *** 911,917 **** { if (flag) { ! conn->flags |= NS_CONN_CHUNKED; } else { ! conn->flags &= ~NS_CONN_CHUNKED; } } --- 911,917 ---- { if (flag) { ! conn->flags |= NS_CONN_WRITE_CHUNKED; } else { ! conn->flags &= ~NS_CONN_WRITE_CHUNKED; } } |