ICanBoogie/HTTP v2.6.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Exception
    • HTTP
      • Headers
      • Request
      • RequestDispatcher

Classes

  • CallableDispatcher
  • DispatcherProvider
  • File
  • FileInfo
  • FileList
  • FileResponse
  • Headers
  • ProvideDispatcher
  • RedirectResponse
  • Request
  • RequestDispatcher
  • RequestOptionsMapper
  • RequestRange
  • Response
  • Status
  • WeightedDispatcher

Interfaces

  • Dispatcher
  • Exception
  • FileOptions
  • RequestMethods
  • RequestOptions
  • ResponseStatus
  • SecurityError

Exceptions

  • AuthenticationRequired
  • ClientError
  • DispatcherNotDefined
  • DispatcherProviderNotDefined
  • ForceRedirect
  • MethodNotSupported
  • NotFound
  • PermissionRequired
  • ServerError
  • ServiceUnavailable
  • StatusCodeNotValid

Functions

  • dispatch
  • get_dispatcher
  • get_initial_request

Class FileResponse

Representation of an HTTP response delivering a file.

ICanBoogie\HTTP\Response implements ICanBoogie\HTTP\ResponseStatus uses ICanBoogie\Accessor\AccessorTrait (not available)
Extended by ICanBoogie\HTTP\FileResponse
Namespace: ICanBoogie\HTTP
Located at FileResponse.php

Methods summary

public static string
# hash_file( string $pathname )

Hashes a file using SHA-348.

Hashes a file using SHA-348.

Parameters

$pathname

Returns

string
A base64 string
protected SplFileInfo
# get_file( )

Returns

SplFileInfo
public
# __construct( string|SplFileInfo $file, ICanBoogie\HTTP\Request $request, array $options = [], array $headers = [] )

Parameters

$file
$request
$options
$headers

Overrides

ICanBoogie\HTTP\Response::__construct
public
# __invoke( )

Changes the status to Status::NOT_MODIFIED if the request's Cache-Control has 'no-cache' and is_modified is false.

Changes the status to Status::NOT_MODIFIED if the request's Cache-Control has 'no-cache' and is_modified is false.

Overrides

ICanBoogie\HTTP\Response::__invoke
protected
# finalize( ICanBoogie\HTTP\Headers & $headers, mixed & $body )

The following headers are always modified:

The following headers are always modified:

  • Cache-Control: sets cacheable to public.
  • Expires: is set to "+1 month".

If the status code is Stauts::NOT_MODIFIED the following headers are unset:

  • Content-Type
  • Content-Length

Otherwise, the following header is set:

  • Content-Type:

Parameters

$headers
Reference to the final header.
$body
Reference to the final body.

Inheritdoc

Overrides

ICanBoogie\HTTP\Response::finalize
protected
# finalize_for_not_modified( ICanBoogie\HTTP\Headers & $headers )

Finalizes the response for Status::NOT_MODIFIED.

Finalizes the response for Status::NOT_MODIFIED.

Parameters

$headers
protected
# finalize_for_partial_content( ICanBoogie\HTTP\Headers & $headers )

Finalizes the response for Status::PARTIAL_CONTENT.

Finalizes the response for Status::PARTIAL_CONTENT.

Parameters

$headers
protected
# finalize_for_other( ICanBoogie\HTTP\Headers & $headers )

Finalizes the response for status other than Status::NOT_MODIFIED or Status::PARTIAL_CONTENT.

Finalizes the response for status other than Status::NOT_MODIFIED or Status::PARTIAL_CONTENT.

Parameters

$headers
protected
# send_file( SplFileInfo $file )

Sends the file.

Sends the file.

Parameters

$file

Codecoverageignore

protected ICanBoogie\HTTP\Headers\ContentType
# get_content_type( )

If the content type returned by the parent is empty the method tries to obtain it from the file, if it fails ICanBoogie\HTTP\FileResponse::DEFAULT_MIME is used as fallback.

If the content type returned by the parent is empty the method tries to obtain it from the file, if it fails ICanBoogie\HTTP\FileResponse::DEFAULT_MIME is used as fallback.

Returns

ICanBoogie\HTTP\Headers\ContentType

Inheritdoc

Overrides

ICanBoogie\HTTP\Response::get_content_type
protected string
# get_etag( )

If the etag returned by the parent is empty the method returns a SHA-384 of the file.

If the etag returned by the parent is empty the method returns a SHA-384 of the file.

Returns

string

Overrides

ICanBoogie\HTTP\Response::get_etag
protected ICanBoogie\DateTime|ICanBoogie\HTTP\Headers\Date
# get_expires( )

If the date returned by the parent is empty the method returns a date created from ICanBoogie\HTTP\FileResponse::DEFAULT_EXPIRES.

If the date returned by the parent is empty the method returns a date created from ICanBoogie\HTTP\FileResponse::DEFAULT_EXPIRES.

Returns

ICanBoogie\DateTime|ICanBoogie\HTTP\Headers\Date

Overrides

ICanBoogie\HTTP\Response::get_expires
protected integer
# get_modified_time( )

Returns the timestamp at which the file was last modified.

Returns the timestamp at which the file was last modified.

Returns

integer
protected boolean
# get_is_modified( )

Whether the file as been modified since the last response.

Whether the file as been modified since the last response.

The file is considered modified if one of the following conditions is met:

  • The If-Modified-Since request header is empty.
  • The If-Modified-Since value is inferior to $modified_time.
  • The If-None-Match value doesn't match $etag.

Returns

boolean
protected ICanBoogie\HTTP\RequestRange
# get_range( )

Returns

ICanBoogie\HTTP\RequestRange
protected
# apply_options( array $options, ICanBoogie\HTTP\Headers|array & $headers )

Parameters

$options
$headers

Methods inherited from ICanBoogie\HTTP\Response

__clone(), __toString(), assert_body_is_valid(), get_age(), get_body(), get_cache_control(), get_content_length(), get_date(), get_is_cacheable(), get_is_fresh(), get_is_validateable(), get_last_modified(), get_location(), get_status(), get_ttl(), send_body(), send_headers(), set_age(), set_body(), set_cache_control(), set_content_length(), set_content_type(), set_date(), set_etag(), set_expires(), set_last_modified(), set_location(), set_status(), set_ttl()

Constants summary

string OPTION_ETAG

Specifies the ETag header field of the response. If it is not defined the SHA-384 of the file is used instead.

Specifies the ETag header field of the response. If it is not defined the SHA-384 of the file is used instead.

# 'etag'
string OPTION_EXPIRES

Specifies the expiration date as a ICanBoogie\DateTime instance or a relative date such as "+3 month", which maps to the Expires header field. The max-age directive of the Cache-Control header field is computed from the current time. If it is not defined ICanBoogie\HTTP\FileResponse::DEFAULT_EXPIRES is used instead.

Specifies the expiration date as a ICanBoogie\DateTime instance or a relative date such as "+3 month", which maps to the Expires header field. The max-age directive of the Cache-Control header field is computed from the current time. If it is not defined ICanBoogie\HTTP\FileResponse::DEFAULT_EXPIRES is used instead.

# 'expires'
string OPTION_FILENAME

Specifies the filename of the file and forces download. The following header are updated: Content-Transfer-Encoding, Content-Description, and Content-Dispositon.

Specifies the filename of the file and forces download. The following header are updated: Content-Transfer-Encoding, Content-Description, and Content-Dispositon.

# 'filename'
string OPTION_MIME

Specifies the MIME of the file, which maps to the Content-Type header field. If it is not defined the MIME is guessed using finfo::file().

Specifies the MIME of the file, which maps to the Content-Type header field. If it is not defined the MIME is guessed using finfo::file().

# 'mime'
string DEFAULT_EXPIRES
# '+1 month'
string DEFAULT_MIME
# 'application/octet-stream'

Constants inherited from ICanBoogie\HTTP\ResponseStatus

STATUS_ACCEPTED, STATUS_BAD_GATEWAY, STATUS_BAD_REQUEST, STATUS_CONFLICT, STATUS_CONTINUE, STATUS_CREATED, STATUS_EXPECTATION_FAILED, STATUS_FORBIDDEN, STATUS_FOUND, STATUS_GATEWAY_TIMEOUT, STATUS_GONE, STATUS_HTTP_VERSION_NOT_SUPPORTED, STATUS_INTERNAL_SERVER_ERROR, STATUS_I_M_A_TEAPOT, STATUS_LENGTH_REQUIRED, STATUS_METHOD_NOT_ALLOWED, STATUS_MOVED_PERMANENTLY, STATUS_MULTIPLE_CHOICES, STATUS_NON_AUTHORITATIVE_INFORMATION, STATUS_NOT_ACCEPTABLE, STATUS_NOT_FOUND, STATUS_NOT_IMPLEMENTED, STATUS_NOT_MODIFIED, STATUS_NO_CONTENT, STATUS_OK, STATUS_PARTIAL_CONTENT, STATUS_PAYMENT_REQUIRED, STATUS_PRECONDITION_FAILED, STATUS_PROXY_AUTHENTICATION_REQUIRED, STATUS_REQUESTED_RANGE_NOT_SATISFIABLE, STATUS_REQUEST_ENTITY_TOO_LARGE, STATUS_REQUEST_TIMEOUT, STATUS_REQUEST_URI_TOO_LONG, STATUS_RESET_CONTENT, STATUS_SEE_OTHER, STATUS_SERVICE_UNAVAILABLE, STATUS_SWITCHING_PROTOCOLS, STATUS_TEMPORARY_REDIRECT, STATUS_UNAUTHORIZED, STATUS_UNSUPPORTED_MEDIA_TYPE, STATUS_USE_PROXY

Properties summary

protected SplFileInfo $file
#
protected ICanBoogie\HTTP\Request $request
#
protected array $options
#

Properties inherited from ICanBoogie\HTTP\Response

$headers, $version

Magic properties

public read-only SplFileInfo $file
public read-only integer $modified_time
public read-only ICanBoogie\HTTP\RequestRange $range
public read-only boolean $is_modified

Magic properties inherited from ICanBoogie\HTTP\Response

$age, $body, $cache_control, $content_length, $content_type, $date, $etag, $expires, $is_cacheable, $is_fresh, $is_private, $is_validateable, $last_modified, $location, $status, $ttl

ICanBoogie/HTTP v2.6.0 API documentation generated by ApiGen