コード例 #1
0
ファイル: views.py プロジェクト: conwetlab/proxy-hosting
    def create(self, request):
        try:
            if request.get_host() != urlparse.urlparse(request.META["HTTP_REFERER"])[1]:
                return HttpResponseServerError(get_xml_error(_(u"Invalid request Referer")), mimetype='application/xml; charset=UTF-8')
        except:
            return HttpResponseServerError(get_xml_error(_(u"Invalid request Referer")), mimetype='application/xml; charset=UTF-8')

        # URI to be called
        if request.POST.has_key('url'):
            url = request.POST['url']
        else:
            return HttpResponseNotFound(get_xml_error(_(u"Url not specified")), mimetype='application/xml; charset=UTF-8')

        # HTTP method, by default is GET
        if request.POST.has_key('method'):
            method = request.POST['method'].upper()
        else:
            method = "GET"

        # Params
        if method != 'GET' and request.POST.has_key('params'):
            # if Content-Type is xml or json then skipping encode function.
            if re.search("application/(json|xml|[a-zA-Z-]+\+xml)|text/xml", request.META["CONTENT_TYPE"]) != None:
                params = request.POST['params'].encode('utf-8')
            else:
                try:
                    params = urlencode(simplejson.loads(request.POST['params']))
                except Exception, e:
                    params = encode_query(request.POST['params'])
コード例 #2
0
ファイル: views.py プロジェクト: conwetlab/proxy-hosting
def proxy_request(request, protocol, domain, path):
    content_type = request.META.get('CONTENT_TYPE', '')
    if content_type == None:
        content_type = ''

    if not content_type.startswith('multipart') and '_method' in request.POST:
        method = request.POST['_method']
        del request.POST['_method']
    else:
        method = request.method.upper()

    raw_data = request.raw_post_data


    try:
        if request.get_host() != urlparse.urlparse(request.META["HTTP_REFERER"])[1]:
            return HttpResponseServerError(get_xml_error(_(u"Invalid request Referer")), mimetype='application/xml; charset=UTF-8')
    except:
        return HttpResponseServerError(get_xml_error(_(u"Invalid request Referer")), mimetype='application/xml; charset=UTF-8')


    url = protocol + '://' + domain + path
    if len(request.GET) > 0:
        url += '?' + request.GET.urlencode()

    response = EZWEB_PROXY.do_request(request, url, method, raw_data)


    # Process cookies
    for key in response.cookies:
        cookie = response.cookies[key]

        if 'path' in cookie:
            cookie['path'] = '/proxy/' + protocol + '/' + urlquote(domain, '') + cookie['path']
        else:
            cookie['path'] = '/proxy/' + protocol + '/' + urlquote(domain, '')

        del cookie['domain']

    return response
コード例 #3
0
ファイル: resource.py プロジェクト: conwetlab/proxy-hosting
        except HttpMethodNotAllowed:
            log_request(request, None, 'access')
            
            response = HttpResponseNotAllowed(self.permitted_methods)
            response.mimetype = self.mimetype
            return response
        except TracedServerError, e:
            log_request(request, None, 'access')
            
            msg = log_detailed_exception(request, e)
        except Exception, e:
            log_request(request, None, 'access')
            
            msg = log_exception(request, e)

        return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
    
    def adaptRequest(self, request):
        request._post, request._files = QueryDict(request.raw_post_data, encoding=request._encoding), datastructures.MultiValueDict()
        
        return request
    
    def dispatch(self, request, target, *args, **kwargs):
        request_method = request.method.upper()
        if request_method not in self.permitted_methods:
            raise HttpMethodNotAllowed
        
        if request_method == 'GET':
            return target.read(request, *args, **kwargs)
        elif request_method == 'POST':
            #PUT and DELETE request are wrapped in a POST request