def createRequest(self, operation, request, data): request_host = request.url().host() request_path = request.url().path() quietthyme_host = QUrl('http://' + prefs['api_base']).host() if self.bearer_token and (quietthyme_host == request_host): #and not(request_path.startswith('/link/callback')): print("Adding QT Auth header: %s", request.url()) request.setRawHeader("Authorization", "Bearer %s" % self.bearer_token) if quietthyme_host == request_host: #TODO Huge hack. only because QT5 cant seeem to consistently communicate over SSL when using sni. ie cloudflare. url = request.url() url.setScheme('http') request.setUrl(url) if self.frame_origin: #adding the current resource request to the security origin witelist. self.frame_origin.addAccessWhitelistEntry("http", "", QWebSecurityOrigin.AllowSubdomains) self.frame_origin.addAccessWhitelistEntry("https", "", QWebSecurityOrigin.AllowSubdomains) self.frame_origin.addAccessWhitelistEntry("qrc", "", QWebSecurityOrigin.AllowSubdomains) self.frame_origin.addAccessWhitelistEntry("data", "", QWebSecurityOrigin.AllowSubdomains) self.frame_origin.addAccessWhitelistEntry("https", request.url().host(), QWebSecurityOrigin.AllowSubdomains) self.frame_origin.addAccessWhitelistEntry("http", request.url().host(), QWebSecurityOrigin.AllowSubdomains) print("Requesting: %s" % request.url()) reply = QNetworkAccessManager.createRequest(self,operation, request, data) return reply
def createRequest(self, operation, request, data): qurl = request.url() if operation == self.GetOperation and qurl.host() == FAKE_HOST: name = qurl.path()[1:] c = current_container() if c.has_name(name): try: return NetworkReply(self, request, c.mime_map.get(name, 'application/octet-stream'), name) except Exception: import traceback traceback.print_exc() return QNetworkAccessManager.createRequest(self, operation, request, data)
def createRequest(self, operation, request, data): qurl = request.url() if operation == self.GetOperation and qurl.host() == FAKE_HOST: name = qurl.path()[1:] c = current_container() if c.has_name(name): try: return NetworkReply(self, request, c.mime_map.get(name, 'application/octet-stream'), name) except Exception: import traceback traceback.print_exc() return QNetworkAccessManager.createRequest(self, operation, request, data)
def createRequest(self, operation, request, data): url = unicode(request.url().toString(QUrl.None)) if operation == self.GetOperation and url.startswith('file://'): path = url[7:] if iswindows and path.startswith('/'): path = path[1:] c = current_container() try: name = c.abspath_to_name(path, root=self.current_root) except ValueError: # Happens on windows with absolute paths on different drives name = None if c.has_name(name): try: return NetworkReply(self, request, c.mime_map.get(name, 'application/octet-stream'), name) except Exception: import traceback traceback.print_exc() return QNetworkAccessManager.createRequest(self, operation, request, data)
def createRequest(self, op, req, device=None): self.reply = None """ if op == 1: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("Head",req.url().toString())) elif op == 2: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("GET",req.url().toString())) elif op == 3: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("PUT",req.url().toString())) elif op == 4: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("POST",req.url().toString())) elif op == 5: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("Delete",req.url().toString())) else: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("CUSTOM",req.url().toString())) """ reply = QNetworkAccessManager.createRequest(self, op, req, device) #reply = NetworkReply(self, reply) return reply
def createRequest(self, op, req, device=None): self.reply = None """ if op == 1: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("Head",req.url().toString())) elif op == 2: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("GET",req.url().toString())) elif op == 3: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("PUT",req.url().toString())) elif op == 4: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("POST",req.url().toString())) elif op == 5: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("Delete",req.url().toString())) else: logging.debug("NetworkAccessManager: Request created - Operation: {}, Url: {}".format("CUSTOM",req.url().toString())) """ reply = QNetworkAccessManager.createRequest(self, op, req, device) #reply = NetworkReply(self, reply) return reply
def createRequest(self, operation, request, data): url = unicode(request.url().toString(QUrl.None)) if operation == self.GetOperation and url.startswith('file://'): path = url[7:] if iswindows and path.startswith('/'): path = path[1:] c = current_container() try: name = c.abspath_to_name(path, root=self.current_root) except ValueError: # Happens on windows with absolute paths on different drives name = None if c.has_name(name): try: return NetworkReply( self, request, c.mime_map.get(name, 'application/octet-stream'), name) except Exception: import traceback traceback.print_exc() return QNetworkAccessManager.createRequest(self, operation, request, data)
def createRequest(self, operation, request, data): qurl = request.url() if operation == QNetworkAccessManager.GetOperation and qurl.host() == FAKE_HOST: name = qurl.path()[1:] if name.startswith(self.mathjax_prefix): base = normpath(P('viewer/mathjax')) path = normpath(os.path.join(base, name.partition('/')[2])) else: base = self.root path = normpath(os.path.join(self.root, name)) if path.startswith(base) and os.path.exists(path): try: with lopen(path, 'rb') as f: data = f.read() data, mime_type = self.preprocess_data(data, path) return NetworkReply(self, request, mime_type, data) except Exception: import traceback self.load_error.emit(name, traceback.format_exc()) if DEBUG: prints('URL not found in book: %r' % qurl.toString()) return QNetworkAccessManager.createRequest(self, operation, request)
def createRequest(self, operation, request, data): url = unicode(request.url().toString(QUrl.None)) operation_name = self.OPERATION_NAMES[operation] debug = [] debug.append(('Request: %s %s' % (operation_name, url))) for h in request.rawHeaderList(): try: d = ' %s: %s' % (h, request.rawHeader(h)) except: d = ' %r: %r' % (h, request.rawHeader(h)) debug.append(d) if data is not None: raw = data.peek(1024) try: raw = raw.decode('utf-8') except: raw = repr(raw) debug.append(' Request data: %s'%raw) self.log.debug('\n'.join(debug)) return QNetworkAccessManager.createRequest(self, operation, request, data)