Class Poco::Net::MediaType
Author: Applied Informatics Software Engineering GmbH and Contributors

# Poco::Net

# class MediaType

Library: Net
Package: Messages
Header: Poco/Net/MediaType.h

## Description

This class represents a MIME media type, consisting of a top-level type, a subtype and an optional set of parameters.

The implementation conforms with RFC 2045 and RFC 2046.

## Member Summary

Member Functions: getParameter, getSubType, getType, hasParameter, matches, matchesRange, operator =, parameters, parse, removeParameter, setParameter, setSubType, setType, swap, toString

## Constructors

### MediaType

MediaType(
const std::string & mediaType
);

Creates the MediaType from the given string, which must have the format <type>/<subtype>{;<parameter>=<value>}.

### MediaType

MediaType(
const MediaType & mediaType
);

Creates a MediaType from another one.

### MediaType

MediaType(
const std::string & type,
const std::string & subType
);

Creates the MediaType, using the given type and subtype.

## Destructor

### ~MediaType

~MediaType();

Destroys the MediaType.

## Member Functions

### getParameter

const std::string & getParameter(
const std::string & name
) const;

Returns the parameter with the given name.

Throws a NotFoundException if the parameter does not exist.

### getSubType

const std::string & getSubType() const;

Returns the sub type.

### getType

const std::string & getType() const;

Returns the top-level type.

### hasParameter

bool hasParameter(
const std::string & name
) const;

Returns true if and only if a parameter with the given name exists.

### matches

bool matches(
const MediaType & mediaType
) const;

Returns true if and only if the type and subtype match the type and subtype of the given media type. Matching is case insensitive.

### matches

bool matches(
const std::string & type,
const std::string & subType
) const;

Returns true if and only if the type and subtype match the given type and subtype. Matching is case insensitive.

### matches

bool matches(
const std::string & type
) const;

Returns true if and only if the type matches the given type. Matching is case insensitive.

### matchesRange

bool matchesRange(
const MediaType & mediaType
) const;

Returns true if the type and subtype match the type and subtype of the given media type. If the MIME type is a range of types it matches any media type withing the range (e.g. "image/*" matches any image media type, "*/*" matches anything). Matching is case insensitive.

### matchesRange

bool matchesRange(
const std::string & type,
const std::string & subType
) const;

Returns true if the type and subtype match the given type and subtype. If the MIME type is a range of types it matches any media type withing the range (e.g. "image/*" matches any image media type, "*/*" matches anything). Matching is case insensitive.

### matchesRange

bool matchesRange(
const std::string & type
) const;

Returns true if the type matches the given type or the type is a range of types denoted by "*". Matching is case insensitive.

### operator =

MediaType & operator = (
const MediaType & mediaType
);

Assigns another media type.

### operator =

MediaType & operator = (
const std::string & mediaType
);

Assigns another media type.

### parameters

const NameValueCollection & parameters() const;

Returns the parameters.

### removeParameter

void removeParameter(
const std::string & name
);

Removes the parameter with the given name.

### setParameter

void setParameter(
const std::string & name,
const std::string & value
);

Sets the parameter with the given name.

### setSubType

void setSubType(
const std::string & subType
);

Sets the sub type.

### setType

void setType(
const std::string & type
);

Sets the top-level type.

### swap

void swap(
MediaType & mediaType
);

Swaps the MediaType with another one.

### toString

std::string toString() const;

Returns the string representation of the media type which is <type>/<subtype>{;<parameter>=<value>}

### parse

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