Poco::OSP::Web

class MediaTypeMapper

Library: OSP/Web
Package: Web
Header: Poco/OSP/Web/MediaTypeMapper.h

Description

The MediaTypeMapper service maps file extensions to MIME media types.

For more information on MIME media types, please see RFC 2045 and RFC 2046.

The MediaTypeMapper can load extension to media type associations from a configuration file. The configuration file has the same format as the Apache mime.types file, used by the Apache mod_mime module (see http://httpd.apache.org/docs/1.3/mod/mod_mime.html).

The mime.types file consists of lines, each containing an association between a media type and zero or more extensions. Media type and extensions are delimited by whitespace. Lines starting with a hash character ('#') are treated as comments and ignored.

The name of the MediaTypeMapper service is "osp.web.mediatype".

Inheritance

Direct Base Classes: Poco::OSP::Service

All Base Classes: Poco::OSP::Service, Poco::RefCountedObject

Member Summary

Member Functions: add, begin, end, find, getDefault, isA, load, map, setDefault, type

Inherited Functions: duplicate, isA, referenceCount, release, type

Types Aliases

ConstIterator

using ConstIterator = SuffixToMediaTypeMap::const_iterator;

Ptr

using Ptr = Poco::AutoPtr < MediaTypeMapper >;

SuffixToMediaTypeMap

using SuffixToMediaTypeMap = std::map < std::string, std::string >;

Constructors

MediaTypeMapper

MediaTypeMapper();

Creates an empty MediaTypeMapper.

Destructor

~MediaTypeMapper virtual

~MediaTypeMapper();

Destroys the MediaTypeMapper.

Member Functions

add

void add(
    const std::string & suffix,
    const std::string & mediaType
);

Adds the suffix->MIME media type mapping if no entry exists for the suffix yet. Suffix is not case sensitive.

begin inline

ConstIterator begin() const;

Returns the begin iterator for the suffix to MIME media type map.

end inline

ConstIterator end() const;

Returns the end iterator for the suffix to MIME media type map.

find

ConstIterator find(
    const std::string & suffix
) const;

Searches a MIME media type for the given suffix. Returns end() for unknown mappings. Note that the search is not case sensitive!

getDefault inline

const std::string & getDefault() const;

Returns the default MIME media type.

Unless another default type has been set with setDefault(), the default type is application/binary.

isA virtual

virtual bool isA(
    const std::type_info & otherType
) const;

load

void load(
    std::istream & str
);

Loads mappings from a stream or file conforming to the Apache mime.types file format. The mappings from the file are added to the existing mappings.

map

const std::string & map(
    const std::string & suffix
) const;

Returns a MIME media type for the given suffix. If no media type has been registered for the given suffix, the default media type (application/binary, unless anothe one has been set) is returned. Note that the search is not case sensitive!

setDefault

void setDefault(
    const std::string & mediaType
);

Sets a default MIME media type for unknown suffixes.

type virtual

virtual const std::type_info & type() const;

Variables

SERVICE_NAME static

static const std::string SERVICE_NAME;

Securely control IoT edge devices from anywhere   Connect a Device