示例#1
0
def get_me_follows(service_urls, auth_token, x_user_agent):

    PATH = 'me/follows'
    url = service_urls.get(CORE_BASE_URL_KEY) + '/' + PATH
    return http_access.fetch_get(url,
                                 auth_token=auth_token,
                                 x_user_agent=x_user_agent)
示例#2
0
def get_playlist_feeds(service_urls, auth_token, x_user_agent, feedIds):

    PATH = 'playlistFeeds'
    url = service_urls.get(PLS_BASE_URL_KEY) + '/' + PATH
    query_params_dict = webob.multidict.MultiDict()
    for id in feedIds:
        query_params_dict.add('id', id)

    return http_access.fetch_get(url,
                                 auth_token=auth_token,
                                 x_user_agent=x_user_agent,
                                 query_params_dict=query_params_dict)
示例#3
0
def get_acc_check(service_urls, user_token, x_user_agent, timestamp, user_name,
                  device_uid):
    PATH = 'ACC_CHECK'
    url = service_urls.get(CORE_BASE_URL_KEY) + '/' + PATH

    query_params_dict = {
        'USER_TOKEN': user_token,
        'timestamp': timestamp,
        'USER_NAME': user_name,
        'DEVICE_UID': device_uid
    }
    return http_access.fetch_get(url,
                                 x_user_agent=x_user_agent,
                                 query_params_dict=query_params_dict)
示例#4
0
    def handler(self, method):
        sent = False
        try:
            #remove channel from path
            #logging.info(self.request.path)
            paths = self.request.path.split('/')
            #logging.info(paths)
            channel = '0'  #default
            path_without_channel = ''
            if len(paths) > 1:
                new_path = ''
                first_item = True
                for item in paths[1:]:
                    #logging.info(item)
                    if item.isdigit() and first_item == True:
                        channel = str(item)
                        first_item = False
                    else:
                        new_path += '/'
                        new_path += item
                path_without_channel = new_path

            #logging.info(self.request.path)
            #logging.info(path_without_channel)
            forwarding_url = ForwardMappings.get_forward_to_url(
                channel, path_without_channel)
            if forwarding_url == None:
                #no mapping found so quite
                self.response.write(
                    'could not find forwarding mapping for : {}'.format(
                        str(self.request.path)))
                self.response.set_status(404)
                return

            url = '{}{}'.format(forwarding_url, path_without_channel)
            #logging.info(self.request.query)
            if self.request.query != None and self.request.query != '':
                url += '?{}'.format(self.request.query)
            ReverseProxyHandler.log_method(
                '====REVERSE PROXY REQUEST=======\n',
                '====END PROXY REQUEST=======\n', self.request.host,
                forwarding_url, self.request.method, url, self.request.headers,
                self.request.body)

            #pass onto to destination url
            resp_code = ''
            resp_content = ''
            resp_headers = {}

            if method == 'POST':
                resp_code, resp_content, resp_headers = http_access.fetch_post(
                    url, self.request.headers, self.request.body, None)
            elif method == 'PUT':
                resp_code, resp_content, resp_headers = http_access.fetch_put(
                    url, self.request.headers, self.request.body, None)
            else:  #GET
                resp_code, resp_content, resp_headers = http_access.fetch_get(
                    url, self.request.headers, None)

            self.response.set_status(resp_code)
            if resp_headers != None:
                for key, value in resp_headers.items():
                    self.response.headers[key] = value
            sent = True
            ReverseProxyHandler.log_method(
                '====REVERSE PROXY RESPONSE=======\n',
                '====END PROXY RESPONSE=======\n', forwarding_url,
                self.request.host, self.request.method, path_without_channel,
                self.response.headers, resp_content, resp_code)
            self.response.write(resp_content)
            return

        except IOError as e:
            if not sent:
                self.response.write('error trying to proxy: {}'.format(str(e)))
                self.response.set_status(404)