def start(self, args=None):
        parser, options = parse_commandline(
            args if args is not None else sys.argv[1:])

        if options.direction is None:
            raise parser.error("Either --forward or --reverse must be given.")

        self.outgoing_context = yield from aiocoap.Context.create_client_context(
            dump_to='/tmp/proxy-out.log')
        proxy = options.direction(self.outgoing_context)
        for kind, data in options.r or ():
            if kind == '--namebased':
                try:
                    name, dest = data.split(':', 1)
                except:
                    raise parser.error(
                        "--namebased needs NAME:DEST as arguments")
                r = NameBasedVirtualHost(name, dest)
            elif kind == '--pathbased':
                try:
                    path, dest = data.split(':', 1)
                except:
                    raise parser.error(
                        "--pathbased needs PATH:DEST as arguments")
                r = SubresourceVirtualHost(path.split('/'), dest)
            elif kind == '--unconditional':
                r = UnconditionalRedirector(data)
            else:
                raise AssertionError('Unknown redirectory kind')
            proxy.add_redirector(r)

        self.proxy_context = yield from aiocoap.Context.create_server_context(
            proxy,
            dump_to='/tmp/proxy-in.log',
            bind=(options.server_address, options.server_port))
Beispiel #2
0
    async def start(self, args=None):
        parser = build_parser()
        options = parser.parse_args(args if args is not None else sys.argv[1:])

        if options.direction is None:
            raise parser.error("Either --forward or --reverse must be given.")

        self.outgoing_context = await aiocoap.Context.create_client_context(dump_to=options.dump_server)
        proxy = options.direction(self.outgoing_context)
        for kind, data in options.r or ():
            if kind == '--namebased':
                try:
                    name, dest = data.split(':', 1)
                except:
                    raise parser.error("--namebased needs NAME:DEST as arguments")
                r = NameBasedVirtualHost(name, dest)
            elif kind == '--pathbased':
                try:
                    path, dest = data.split(':', 1)
                except:
                    raise parser.error("--pathbased needs PATH:DEST as arguments")
                r = SubresourceVirtualHost(path.split('/'), dest)
            elif kind == '--unconditional':
                r = UnconditionalRedirector(data)
            else:
                raise AssertionError('Unknown redirectory kind')
            proxy.add_redirector(r)

        self.proxy_context = await server_context_from_arguments(proxy, options, dump_to=options.dump_client)