From 7ee2de0fe2af6160a5fbf93d8004ffed492ee442 Mon Sep 17 00:00:00 2001 From: IMMEDIATO Marco Date: Thu, 6 Jul 2017 16:50:37 +0200 Subject: [PATCH 1/2] sending cookie_secure options to phantom script and added phantomjs command options --- src/page_exporter/__init__.py | 2 +- src/page_exporter/scripts/capture.js | 5 ++++- src/page_exporter/utils.py | 8 +++++++- tests/example_client/settings/default.py | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/page_exporter/__init__.py b/src/page_exporter/__init__.py index 007cc69..8b653de 100644 --- a/src/page_exporter/__init__.py +++ b/src/page_exporter/__init__.py @@ -3,7 +3,7 @@ import os NAME = 'django_page_exporter'.replace('_', '-') -VERSION = __version__ = (0, 3, 1, 'final', 0) +VERSION = __version__ = (0, 4, 0, 'alpha', 0) __author__ = 'Marco Immediato' diff --git a/src/page_exporter/scripts/capture.js b/src/page_exporter/scripts/capture.js index 6d27363..0687322 100644 --- a/src/page_exporter/scripts/capture.js +++ b/src/page_exporter/scripts/capture.js @@ -87,7 +87,8 @@ if (config.cookie_name != null) { phantom.addCookie({ 'name': config.cookie_name || 'sessionid', 'value': config.cookie_value || '', - 'domain': config.cookie_domain || 'localhost' + 'domain': config.cookie_domain || 'localhost', + 'secure': config.cookie_secure || false }); } @@ -133,5 +134,7 @@ page.open(address, function (status) { } + }else if(status == 'fail'){ + phantom.exit(); } }); \ No newline at end of file diff --git a/src/page_exporter/utils.py b/src/page_exporter/utils.py index 8b7f8e1..e909a38 100644 --- a/src/page_exporter/utils.py +++ b/src/page_exporter/utils.py @@ -1,5 +1,6 @@ from threading import Timer +from django.conf import settings from django.utils import six import os import logging @@ -42,6 +43,7 @@ def phantomjs_command_kwargs(): def phantomjs_command(): cmd = conf.PHANTOMJS_CMD cmd = [cmd] + cmd_optz = conf.CLI_ARGS # Concatenate with capture script app_path = os.path.dirname(__file__) @@ -51,7 +53,8 @@ def phantomjs_command(): capture = os.path.join(app_path, 'scripts', capture) assert os.path.exists(capture), 'Cannot find %s' % capture - return cmd + [capture] + + return cmd + cmd_optz + [capture] PHANTOMJS_CMD = phantomjs_command() @@ -97,6 +100,9 @@ def page_capture(stream, url, method=None, width=None, height=None, cmd += ['--cookie_domain=%s' % cookie_domain] if page_status: cmd += ['--page_status=%s' % page_status] + if getattr(settings, 'SESSION_COOKIE_SECURE', False): + cmd += ['--cookie_secure=true'] + logger.debug(cmd) # Run PhantomJS process proc = subprocess.Popen(cmd, **phantomjs_command_kwargs()) diff --git a/tests/example_client/settings/default.py b/tests/example_client/settings/default.py index 87c2bad..b175d54 100644 --- a/tests/example_client/settings/default.py +++ b/tests/example_client/settings/default.py @@ -90,4 +90,7 @@ PAGE_EXPORTER_PHANTOMJS_CMD = os.path.join(os.path.dirname(__file__), '..', 'phantomjs', 'phantomjs') +PAGE_EXPORTER_WAIT = '10000' +PAGE_EXPORTER_CLI_ARGS = ['--ignore-ssl-errors=true', '--ssl-protocol=any'] + from .logging_conf import * # noqa From 8eb5e67f0c8ad59e45599dddf16c0a8c75748474 Mon Sep 17 00:00:00 2001 From: IMMEDIATO Marco Date: Thu, 6 Jul 2017 16:51:30 +0200 Subject: [PATCH 2/2] 0.4 --- CHANGES | 5 +++++ src/page_exporter/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index aa70bac..13dbf15 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +Release 0.4 +----------- + +* sending cookie_secure options to phantom script and added phantomjs command options + Release 0.3.1 ------------- diff --git a/src/page_exporter/__init__.py b/src/page_exporter/__init__.py index 8b653de..3d132da 100644 --- a/src/page_exporter/__init__.py +++ b/src/page_exporter/__init__.py @@ -3,7 +3,7 @@ import os NAME = 'django_page_exporter'.replace('_', '-') -VERSION = __version__ = (0, 4, 0, 'alpha', 0) +VERSION = __version__ = (0, 4, 0, 'final', 0) __author__ = 'Marco Immediato'