Sends a response containing information about the received event.
Handles downloading of static files and resources.
Handles downloading of static files and resources.
To trigger a download, send a org.mashupbots.socko.handlers.StaticFileRequest or org.mashupbots.socko.handlers.StaticResourceRequest message from your routes.
org.mashupbots.socko.handlers.StaticContentHandler performs HTTP compression and also uses the
If-Modified-Since
header for browser side caching.
org.mashupbots.socko.handlers.StaticContentHandler uses lots of disk IO (blocking code). Please run it using a
router with PinnedDispatcher
(a thread per actor) or BalancingDispatcher
.
For example:
router = actorSystem.actorOf(Props(new StaticContentHandler(StaticContentHandlerConfig())) .withRouter(FromConfig()).withDispatcher("myDispatcher"), "myRouter")
Configuration in application.conf
:
myDispatcher { executor = "thread-pool-executor" type = PinnedDispatcher } akka { event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] loglevel=DEBUG actor { deployment { /myRouter { router = round-robin nr-of-instances = 5 } } } }
HTTP ETag
header is used.
Request #1 Headers ------------------ GET /file1.txt HTTP/1.1 Response #1 Headers ------------------ HTTP/1.1 200 OK Date: Tue, 01 Mar 2011 22:44:26 GMT ETag: "686897696a7c876b7e" Expires: Tue, 01 Mar 2012 22:44:26 GMT Cache-Control: private, max-age=31536000 Request #2 Headers ------------------ GET /file1.txt HTTP/1.1 If-None-Match: "686897696a7c876b7e" Response #2 Headers ------------------ HTTP/1.1 304 Not Modified Date: Tue, 01 Mar 2011 22:44:28 GMT
HTTP If-Modified-Since
header is used
Request #1 Headers ------------------ GET /file1.txt HTTP/1.1 Response #1 Headers ------------------ HTTP/1.1 200 OK Date: Tue, 01 Mar 2011 22:44:26 GMT Last-Modified: Wed, 30 Jun 2010 21:36:48 GMT Expires: Tue, 01 Mar 2012 22:44:26 GMT Cache-Control: private, max-age=31536000 Request #2 Headers ------------------ GET /file1.txt HTTP/1.1 If-Modified-Since: Wed, 30 Jun 2010 21:36:48 GMT Response #2 Headers ------------------ HTTP/1.1 304 Not Modified Date: Tue, 01 Mar 2011 22:44:28 GMT
HTTP Accept-Encoding
header is used by the caller to nominate their supported compression
algorithm. We return the compression format used in the Content-Encoding
header.
Request ------- GET /encrypted-area HTTP/1.1 Host: www.example.com Accept-Encoding: gzip, deflate Response -------- HTTP/1.1 200 OK Content-Encoding: gzip
If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive
Configuration for org.mashupbots.socko.handlers.StaticContentHandler.
Configuration for org.mashupbots.socko.handlers.StaticContentHandler.
This can also be loaded from an externalized AKKA configuration file. For example:
static-content-config { # CSV list of root paths from while files can be served. root-file-paths=/home/me/path1,/home/me/path2 # Temporary directory where compressed files can be stored. # Defaults to the `java.io.tmpdir` system property if setting is omitted temp-dir=localhost # Max number of files and resources to store in the local in memory cache # Defaults to storing 1000 items if setting is omitted server-cache-max-size=1000 # Maximum size of files (in bytes) to be cached. Files larger than this will # not be cached and will be served from the file system or resorce. # Defaults to 100K if setting is omitted server-cache-max-file-size=102400 # Number of seconds files will be cached in local memory # Defaults to 3600 if setting is omitted server-cache-timeout=3600 # Number of seconds before a browser should check back with the server if a file has been updated. # This setting is used to drive the `Expires` and `Cache-Control` HTTP headers. # Defaults to 3600 if setting is omitted browser-cache-timeout=3600 }
can be loaded as follows:
object MyStaticContentHandlerConfig extends ExtensionId[StaticContentHandlerConfig] with ExtensionIdProvider { override def lookup = MyStaticContentHandlerConfig override def createExtension(system: ExtendedActorSystem) = new StaticContentHandlerConfig(system.settings.config, "static-content-config") } val myStaticContentHandlerConfig = MyStaticContentHandlerConfig(actorSystem)
List of root paths from while files can be served.
This is enforced to stop relative path type attacks; e.g. ../etc/passwd
Temporary directory where compressed files can be stored.
Defaults to the java.io.tmpdir
system property.
Local in memory cache to store file meta and content. Defaults to storing 1000 items.
Maximum size of file contents to cache in memory
The contents of files under this limit is cached in memory for serverCacheTimeoutSeconds
. Requests for this file
will be served by the contents stored in memory rather than the file system.
Files larger than this limit are served by reading from the file system for every request.
Defaults to 100K. 0
indicates that files will not be cached in memory.
Number of seconds file meta data (such as file name, size, timestamp and hash) and file contents will be cached in memory. After this time, cache data will be removed and file meta data will and contents will have to be read from the file system.
Note that if serverCacheMaxFileSize
is 0 and serverCacheTimeoutSeconds
is > 0, then only file meta data
will be cached in memory.
Defaults to 1 hour. 0
means files will NOT be cached.
Number of seconds before a browser should check back with the server if a file has been updated.
This setting is used to drive the Expires
and Cache-Control
HTTP headers.
Defaults to 1 hour. 0
means cache headers will not be sent to the browser.
Message to be sent to org.mashupbots.socko.handlers.StaticContentHandler for it to download the specified file
Message to be sent to org.mashupbots.socko.handlers.StaticContentHandler for it to download the specified file
HTTP Request event
File to download to the client
Number of seconds to cache file meta data and contents. If None
, the
default value specified in org.mashupbots.socko.handlers.StaticContentHandlerConfig will be used.
Number of seconds the file is to be cached by the browser. If None
, the
default value specified in org.mashupbots.socko.handlers.StaticContentHandlerConfig will be used.
Message to be sent to org.mashupbots.socko.handlers.StaticContentHandler for it to download the specified file
Message to be sent to org.mashupbots.socko.handlers.StaticContentHandler for it to download the specified file
HTTP Request event
Classpath of resource to load (without a leading "/"). For example: META-INF/mime.types
.
Number of seconds to cache file meta data and contents. If None
, the
default value specified in org.mashupbots.socko.handlers.StaticContentHandlerConfig will be used.
Number of seconds the file is to be cached by the browser. If None
, the
default value specified in org.mashupbots.socko.handlers.StaticContentHandlerConfig will be used.
Sends a response containing information about the received event.
We use this in our testing of Socko