[Libwebsockets] Sending close codes from server to client

Andy Green andy at warmcat.com
Thu Mar 18 06:35:02 CET 2021



On 3/17/21 10:09 PM, Zendels, Michael wrote:
> Hi Andy,
> 
>      Thank you for the quick reply. I'm sorry I was confusing, we are using more recent libwebsocket code, I was just looking at the code when the change of checking close codes first went in. What we are wondering about is what are the Autobahn tests, and why is it required that a close code of 1013 "Try Again Later" get converted to 1002 LWS_CLOSE_STATUS_PROTOCOL_ERR? It seems like a value of 1013 should be a valid reply according to https://www.iana.org/assignments/websocket/websocket.xml#close-code-number.

lws existed before even RFC6455 was ratified, getting on for 11 years 
ago... 1013 is not listed in RFC6455.  They specify 1011 as valid, and 
1015 as reserved, and a hole for 1012, 1013 and 1014.

Later the IANA assigned the ones in the reserved hole, 1014 as late as 2016.

     <record>
       <value>1012</value>
       <description>Service Restart</description>
       <contact><xref type="person" data="Alexey_Melnikov"/></contact>
       <xref type="uri" 
data="http://www.ietf.org/mail-archive/web/hybi/current/msg09670.html"/>
     </record>
     <record>
       <value>1013</value>
       <description>Try Again Later</description>
       <contact><xref type="person" data="Alexey_Melnikov"/></contact>
       <xref type="uri" 
data="http://www.ietf.org/mail-archive/web/hybi/current/msg09670.html"/>
     </record>
     <record date="2016-10-10">
       <value>1014</value>
       <description>The server was acting as a gateway or proxy and 
received an
         invalid response from the upstream server. This is similar to 
502 HTTP
         Status Code.</description>
       <contact><xref type="person" data="Alexey_Melnikov"/></contact>
       <xref type="uri" 
data="https://www.ietf.org/mail-archive/web/hybi/current/msg10748.html"/>
     </record>

It seems all we need to do is accept those defined-after-RFC6455 ones 
(and 1015 although I doubt that appears in the wild).

Here's a patch on main that should do that

https://libwebsockets.org/git/libwebsockets/commit?id=f87546ef7269b9bb1ece1b5556f6f66ab23509f0

-Andy


More information about the Libwebsockets mailing list