stone54321277 / unitt

Automatically exported from code.google.com/p/unitt
0 stars 0 forks source link

Possible issue in close function #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
trunk (WebSocket.m)
====================

If I send close from application logic the server always receives a close with 
status code invalid UTF-8; The WebSocketCloseStatusInvalidUtf8 is an error that 
should be received from the server, not send when I try to close the connection 
via [mySocket close];

- (void) close
{
    [self close:WebSocketCloseStatusNormal message:nil];
}

- (void) close:(NSUInteger) aStatusCode message:(NSString*) aMessage
{
    readystate = WebSocketReadyStateClosing;
    //any rev before 10 does not perform a UTF8 check
    if (self.config.version < WebSocketVersion10)
    {
        [self sendClose:aStatusCode message:aMessage];        
    }
    else
    {
        if (aMessage && [aMessage canBeConvertedToEncoding:NSUTF8StringEncoding])
        {
            [self sendClose:aStatusCode message:aMessage];
        }
        else
        {
            [self sendClose:WebSocketCloseStatusInvalidUtf8 message:nil];
        }
    }
    isClosing = YES;
}

CHANGE (WebSocket.m)
======================

- (void) close
{
    [self close:WebSocketCloseStatusNormal message:nil];
}

- (void) close:(NSUInteger) aStatusCode message:(NSString*) aMessage
{
    readystate = WebSocketReadyStateClosing;
    //any rev before 10 does not perform a UTF8 check
    if (self.config.version < WebSocketVersion10)
    {
        [self sendClose:aStatusCode message:aMessage];        
    }
    else
    {
        if (aMessage && [aMessage canBeConvertedToEncoding:NSUTF8StringEncoding])
        {
            [self sendClose:aStatusCode message:aMessage];
        }
        else
        {
            [self sendClose:WebSocketCloseStatusInvalidUtf8 message:nil];
        }
    }
    isClosing = YES;
}

Original issue reported on code.google.com by andre.moencher@gmail.com on 12 Oct 2011 at 8:25

GoogleCodeExporter commented 9 years ago
Sorry, 
typo in the necessary CHANGE above.

CHANGE (WebSocket.m)
======================

- (void) close
{
    [self close:WebSocketCloseStatusNormal message:nil];
}

- (void) close:(NSUInteger) aStatusCode message:(NSString*) aMessage
{
    readystate = WebSocketReadyStateClosing;
    //any rev before 10 does not perform a UTF8 check
    if (self.config.version < WebSocketVersion10)
    {
        [self sendClose:aStatusCode message:aMessage];        
    }
    else
    {
        if (aMessage && [aMessage canBeConvertedToEncoding:NSUTF8StringEncoding])
        {
            [self sendClose:aStatusCode message:aMessage];
        }
        else
        {
            [self sendClose:aStatusCode message:nil];
        }
    }
    isClosing = YES;
}

Original comment by andre.moencher@gmail.com on 12 Oct 2011 at 8:35

GoogleCodeExporter commented 9 years ago
For version 10, both the client and server are supposed to throw an appropriate 
error when invalid utf8 text is sent in a message. However, I think I need to 
update that method anyways. I believe it is supposed to application data, not 
just text. I'll take a second look on Monday and tighten this up.

Original comment by joshuadmorris@gmail.com on 16 Oct 2011 at 8:35

GoogleCodeExporter commented 9 years ago
It is supposed to be UTF8 text in the message body (if any application data is 
included). The specification says to fail with the UTF failure code if we 
receive text that is not UTF8. However, I like your take on it. The client 
adapter received it from the caller, not the server. I will put in the 
requested change. Good Idea!

Original comment by joshuadmorris@gmail.com on 18 Oct 2011 at 5:05

GoogleCodeExporter commented 9 years ago

Original comment by joshuadmorris@gmail.com on 1 Dec 2011 at 10:54

GoogleCodeExporter commented 9 years ago

Original comment by joshuadmorris@gmail.com on 31 Jan 2012 at 6:32