Changes between Initial Version and Version 1 of Ticket #12952


Ignore:
Timestamp:
Feb 19, 2015, 11:41:20 AM (6 years ago)
Author:
Artur Delura
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12952 – Description

    initial v1  
    11Working on ticket:12612 we found out that we need to allow user to add flag `withCredentials` and some extra headers to XHR object in filetools plugins. Use case for this is to allow cross domain requests.
     2
     3Following [https://github.com/ckeditor/ckeditor-dev/blob/major/plugins/filetools/plugin.js#L463-L471 this] example I tried to customize a bit my request object. I end up with:
     4
     5{{{
     6CKEDITOR.replace( 'editor', function() {
     7  CKEDITOR.fileTools.fileLoader.prototype.sendRequest = function() {
     8          var formData = new FormData(),
     9                        xhr = this.xhr;
     10
     11                formData.append( 'upload', this.file, this.fileName );
     12                xhr.withCredentials = true; // Extra lines
     13                xhr.setRequestHeader( 'X-PINGOTHER', 'pingpong' ); // Extra lines
     14                xhr.open( 'POST', this.uploadUrl, true );
     15                xhr.send( formData );
     16        };
     17} );
     18}}}
     19
     20Shortcomings of this solution are:
     21* We overwrite global function `sendRequest` which influence all editor instances while option`imageUploadUrl` is unique for all editor isntances.
     22* We have to wait for plugin to be loaded and editor instance as well to overwrite this method. If user have got a few editors he have to impelement special mechanism to overwrite this function when first editor instance is loaded. Or maybe there is a global event which fire when plugin is loaded?
     23
     24We got at least two sulutions for this:
     25* We can add extra config option like:
     26{{{
     27xhrData =  {
     28    withCredentials: true,
     29    headers: {
     30        'X-HEADER-NAME': "X-HEADER VALUE"
     31    }
     32};
     33}}}
     34
     35And function send request will take into consideration {{{xhrData}}} config options and set flag and headers. This is simples solution but don't allow user whole freedom.
     36
     37* Second option is to fire events like `prerequest` which will have an xhr object as a property and user would make whatever he wants with this.
© 2003 – 2021 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy