AJAX File Browser Request Pipeline

The IT Hit WebDAV AJAX library, that IT Hit AJAX File Browser is built on, provides events that fire when sending data to the server and when data is available on a client side. In this event handlers, you can change any data submitted between client and server.

Modifying Data Before Sending Request

The OnBeforeRequestSend event is fired before request is being submitted to the server and provides all information that is used when creating the request such as URL, HTTP verb, headers and request body:

function onBeforeRequestSend(requestData){
    // HTTP method and URL
    oTD.value += requestData.Method + ' ' + requestData.Href;

    // headers
    for(var header in requestData.Headers){
        oTD.value += '\n' + header + ': ' +  requestData.Headers[header];
    }

    // request body
    oTD.value += '\n' + requestData.Body + '\n';
}


...


var ajaxFileBrowser = new  ITHit.WebDAV.Client.AjaxFileBrowser.Controller('AjaxFileBrowserContainer', 'http://webdavserver.com/', 'height: 500px; width: 500px');
ITHit.Events.AddListener(ajaxFileBrowser.GetSession(), 'OnBeforeRequestSend', onBeforeRequestSend);

In your event handler, you can change the URL and verb, modify any headers and update the request body.

Tunneling

Tunneling is required if you would like to submit all requests using only GET and POST verbs only and avoid using WebDAV-specific verbs such as PROPFIND, PROPRATCH, OPTIONS, REPORT, etc.

To configure tunneling attach your OnBeforeRequestSend handler and change HTTP method name to GET (or any other verb). The original verb is usually passed to the server as a custom header:

function onBeforeRequestSend(requestData){
    requestData.Headers['Method'] = requestData.Method;
    requestData.Method = 'GET';
}

Note that your WebDAV server must support tunneling, IT Hit WebDAV Server Engine does not support tunneling by default.

Microsoft Office requires full WebDAV Class 2 support, it would not work with tunneling.

Modifying Data After Receiving a Response

The OnResponse event fires when the data is received from the server. In your event handler, you can update any data received from the server.

function onResponse(responceData) {

    // get HTTP status and description
    oTD.value += '\n\n' + responceData.Status + ' ' + responceData.StatusDescription;
    // get headers
    for (var header in responceData.Headers) {
        oTD.value += '\n' + header + ': ' + responceData.Headers[header];
    }
    // get request body
    oTD.value += '\n' + responceData.BodyText + '\n-----';
}


...


ITHit.Events.AddListener(ajaxFileBrowser.GetSession(), 'OnResponse', onResponse);

 

AJAX File Browser Control Events Demo

Next Article:

Getting Started with IT Hit AJAX File Browser v2.0 and Earlier