Commits

Anonymous committed ef88804

ws_accept: to Service

Comments (0)

Files changed (3)

src/amall_http_server.ml

     type websocket_accepter
     ;
 
-    (* [ws_accept subprotocol_opt handler] -- websocket connection is accepted,
-       subprotocol will be sent to client.
-       [subprotocol] can be:
-       - [None] for "client hadn't specified which subprotocols he can use"
-         or "no one of client's protocols is acceptable" (it's up to websocket
-         client to close connection when it proposed subprotocols but server
-         can't accept any of them).
-       - [Some p] for "server will use protocol [p]".  Note: [p] must be
-         chosen from the list returned by [Amall_http.ws_protocols request],
-         otherwise the server will drop this connection with runtime error
-         (it will not count as "graceful websocket connection shutdown"!).
-       Take a look at RFC 6455, section 4.2.2, for the reasons of such
-       seemingly strange behaviour of server's [subprotocol] choice.
-       However, authentication, redirects, Origin checking are not implemented
-       now.
-     *)
+    (* see [Amall_http_service.Service(IO)(I).ws_accept] *)
     value ws_accept : option string -> 
       ( (Websocket.Server(IO)(I)).handler unit) ->
       websocket_accepter

src/amall_http_service.ml

       T.websocket_service_func
     ;
 
+    (* [ws_accept subprotocol_opt handler] -- websocket connection is accepted,
+       subprotocol will be sent to client.
+       [subprotocol] can be:
+       - [None] for "client hadn't specified which subprotocols he can use"
+         or "no one of client's protocols is acceptable" (it's up to websocket
+         client to close connection when it proposed subprotocols but server
+         can't accept any of them).
+       - [Some p] for "server will use protocol [p]".  Note: [p] must be
+         chosen from the list returned by [Amall_http.ws_protocols request],
+         otherwise the server will drop this connection with runtime error
+         (it will not count as "graceful websocket connection shutdown"!).
+       Take a look at RFC 6455, section 4.2.2, for the reasons of such
+       seemingly strange behaviour of server's [subprotocol] choice.
+       However, authentication, redirects, Origin checking are not implemented
+       now.
+     *)
+    value ws_accept :
+      option string -> (Websocket.Server(IO)(I)).handler unit ->
+      HS.websocket_accepter
+    ;
+
     value mount_websocket :
       endpoint websocket_service_func ->
       websocket_service_func ->
     value it_post_vars = HS.it_post_vars
     ;
 
+    value ws_accept = HS.ws_accept
+    ;
 
     value default_http_fallback _segpath rq =
       (* todo: escape chars for html *)

tests/test_websocket_service.ml

      let n = srv_num.val in let () = incr srv_num in
      let () = amdbg "service: [%i] got websocket request on %s" n txt in
      let () = Hashtbl.add clients n outws in
-     S.HS.ws_accept None &
+     S.ws_accept None &
      fun opcode_in ->
        let () = amdbg "service: [%i] entering" n in
        match opcode_in with