webthing/server.py
def get(self, thing_id='0'):
        """
        Handle a GET request, including websocket requests.

        thing_id -- ID of the thing this request is for
        """
        self.thing = self.get_thing(thing_id)
        if self.thing is None:
            self.set_status(404)
            self.finish()
            return

        if self.request.headers.get('Upgrade', '').lower() == 'websocket':
            yield tornado.websocket.WebSocketHandler.get(self)
            return

        self.set_header('Content-Type', 'application/json')
        ws_href = '{}://{}'.format(
            'wss' if self.request.protocol == 'https' else 'ws',
            self.request.headers.get('Host', '')
        )

        description = self.thing.as_thing_description()
        description['links'].append({
            'rel': 'alternate',
            'href': '{}{}'.format(ws_href, self.thing.get_href()),
        })

        self.write(json.dumps(description))
        self.finish()
def get(self, thing_id='0'):
        self.thing = self.get_thing(thing_id)
        if self.thing is None:
            self.set_status(404)
            self.finish()
            return

        if self.request.headers.get('Upgrade', '').lower() == 'websocket':
            yield tornado.websocket.WebSocketHandler.get(self)
            return

        self.set_header('Content-Type', 'application/json')
        ws_href = '{}://{}'.format(
            'wss' if self.request.protocol == 'https' else 'ws',
            self.request.headers.get('Host', '')
        )

        description = self.thing.as_thing_description()
        description['links'].append({
            'rel': 'alternate',
            'href': '{}{}'.format(ws_href, self.thing.get_href()),
        })

        self.write(json.dumps(description))
        self.finish()
def get ( self , thing_id = '0' ) : self . thing = self . get_thing ( thing_id ) if self . thing is None : self . set_status ( 404 ) self . finish ( ) return if self . request . headers . get ( 'Upgrade' , '' ) . lower ( ) == 'websocket' : yield tornado . websocket . WebSocketHandler . get ( self ) return self . set_header ( 'Content-Type' , 'application/json' ) ws_href = '{}://{}' . format ( 'wss' if self . request . protocol == 'https' else 'ws' , self . request . headers . get ( 'Host' , '' ) ) description = self . thing . as_thing_description ( ) description [ 'links' ] . append ( { 'rel' : 'alternate' , 'href' : '{}{}' . format ( ws_href , self . thing . get_href ( ) ) , } ) self . write ( json . dumps ( description ) ) self . finish ( )
Handle a GET request, including websocket requests.

        thing_id -- ID of the thing this request is for
Handle a GET request including websocket requests .