Or you can try to replace ReturnCharData in return.c and see if this works (i did not test it):

static int
ReturnCharData(Ns_Conn *conn, int status, CONST char *data, int len,
               CONST char *type, int sendRaw)
{
    Conn        *connPtr = (Conn *) conn;
    int          result;
    Tcl_Encoding enc;
    Tcl_DString  type_ds;
    int          new_type = NS_FALSE;

    if (conn->flags & NS_CONN_SKIPBODY) {
        data = NULL;
        len = 0;
    }
    if (len < 0) {
        len = data ? strlen(data) : 0;
    }
    if (len > 0 && !sendRaw) {
        /*
         * Make sure we know what output encoding (if any) to use.
         */
        NsComputeEncodingFromType(type, &enc, &new_type, &type_ds);
        if (new_type) {
            type = Tcl_DStringValue(&type_ds);
        }
        if (enc != NULL) {
            connPtr->encoding = enc;
            conPtr->flags |= NS_CONN_WRITE_CHUNKED;
        } else if (connPtr->encoding == NULL) {
            sendRaw = NS_TRUE;
        }
    }
    Ns_ConnSetRequiredHeaders(conn, type, len);
    Ns_ConnQueueHeaders(conn, status);
    if (sendRaw) {
        result = Ns_WriteConn(conn, data, len);
    } else {
        result = Ns_WriteCharConn(conn, data, len);
    }
    if (result == NS_OK) {
        result = Ns_ConnClose(conn);
    }
    if (new_type) {
        Tcl_DStringFree(&type_ds);
    }

    return result;
}

Vlad Seryakov wrote:
I think the only solution here will be to use Chunked-Encoding to output encoded content, in this case Content-Length should be removed fromthe headers.

Ns_ConnWriteVChars handles that, so it shoudl be chnaged i guess.

Bernd Eidenschink wrote:
Am Mittwoch, 12. Juli 2006 15:23 schrieb Bernd Eidenschink:
it looks like the mechanism of changing the encoding works as expected, but
the computation of the correct contentlength not.
ok. I think this is going on:

1. NsTclReturnObjCmd
If ns_return is called _without_ -binary switch, Ns_ConnReturnCharData is called. The length is computed from the UTF-8 representation.

2. Ns_ConnReturnCharData
calls

3. ReturnCharData
Knows what output encoding to use. If not UTF-8, it will call
Ns_WriteCharConn

...BUT BEFORE...

4.
Ns_ConnSetRequiredHeaders
calls Ns_ConnSetLengthHeader
(Set the Content-Length output header)

for

5.
Ns_ConnQueueHeaders
calls NS_ConnConstructHeaders
where
"Update the response length value directly from the header to be sent, i.e., don't trust programmers"

So the content-length is set.

NOW:

7. Ns_WriteCharConn is called, calls
Ns_ConnWriteChars
that with the help of Ns_ConnWriteVChars encodes
with the help of "Tcl_UtfToExternal" to the final encoding.

I can be fundamentally wrong, but it seems to me like the whatever-it-will-become final encoding length should be computed earlier...

What do you think?

Bernd.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
naviserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/naviserver-devel





--
Vlad Seryakov
571 262-8608 office
[EMAIL PROTECTED]
http://www.crystalballinc.com/vlad/

Reply via email to