Sandcat 4.0 comes with response preview handlers for the most common web file formats. This includes CSS, Flash, HTML, common image formats (bmp, gif, ico, jpg, png and svg), JavaScript, JSON, text and XML files. This page explains how you can add support for additional response formats.
In order to add a new preview handler, you must use the Sandcat:RegisterPreviewHandler() method. This method needs three parameters:
{
"name": "My Preview Handler Extension",
"version": "1.0",
"author": "Syhunt Team",
"script": {
"filename": "mypreview.lua",
"init": "MyPreview:register()",
}
}
mypreview.lua:
MyPreview = {}
function MyPreview:register() -- will be called during startup
Sandcat:RegisterPreviewHandler('mypreviewforfoo',self.HandleFoo,'foo','text/foo')
end
function MyPreview:HandleFoo(data)
local source = data.responsetext
-- do something with source here --
data.previewhtml = '<b>Your preview html code</b>'
end
data will contain the following keys with details about the request being previewed:
contenttype | string | The content type extracted from the response headers |
previewhtml | string | Allows you to set the HTML/CSS that will be loaded as the preview. JavaScript and TIScript are not allowed. |
requestheaders | string | All the request headers |
responsefilename | string | Filename of a temporary file containing the decompressed response stream |
responseheaders | string | All the response headers |
responsetext | string | The response as a text |
url | string | The request URL |
warnempty | boolean | If set true, notifies Sandcat that the response is empty or incomplete |