From 7e7880c556edfd5a2da2f7b2869c7fedd4bbf2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=B0=E6=96=87?= Date: Wed, 13 Jan 2016 18:19:59 +0800 Subject: [PATCH] feat: change xhr.withCredentials as prop config, default false --- README.md | 1 + src/AjaxUploader.jsx | 2 ++ src/Upload.jsx | 2 ++ src/request.js | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 890e044b..9562bbf2 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ React.render(, container); |onSuccess | function | | success callback | |onProgress | function || progress callback, only for modern browsers| |beforeUpload| function |null| before upload check, return false or a rejected Promise will stop upload, only for modern browsers| +| withCredentials | boolean | false | ajax upload with cookie send | #### onError arguments diff --git a/src/AjaxUploader.jsx b/src/AjaxUploader.jsx index 251b90fd..cfa45bc6 100644 --- a/src/AjaxUploader.jsx +++ b/src/AjaxUploader.jsx @@ -8,6 +8,7 @@ const AjaxUploader = React.createClass({ onStart: PropTypes.func, data: PropTypes.object, beforeUpload: PropTypes.func, + withCredentials: PropTypes.bool, }, onChange(e) { @@ -85,6 +86,7 @@ const AjaxUploader = React.createClass({ filename: props.name, file: file, data: data, + withCredentials: props.withCredentials, onProgress: e => { props.onProgress(e, file); }, diff --git a/src/Upload.jsx b/src/Upload.jsx index 70d6f921..8e1c12cc 100644 --- a/src/Upload.jsx +++ b/src/Upload.jsx @@ -19,6 +19,7 @@ const Upload = React.createClass({ accept: PropTypes.string, multiple: PropTypes.bool, beforeUpload: PropTypes.func, + withCredentials: PropTypes.bool, }, getDefaultProps() { @@ -33,6 +34,7 @@ const Upload = React.createClass({ onSuccess: empty, multiple: false, beforeUpload: null, + withCredentials: false, }; }, diff --git a/src/request.js b/src/request.js index 754947a7..92fd94f3 100644 --- a/src/request.js +++ b/src/request.js @@ -55,7 +55,7 @@ export default function upload(option) { option.onSuccess(getBody(xhr)); }; - if ('withCredentials' in xhr) { + if (option.withCredentials && 'withCredentials' in xhr) { xhr.withCredentials = true; }