man-pages/man3/LWP::MediaTypes.3pm.html
2021-03-31 01:06:50 +01:00

205 lines
4.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of LWP::MediaTypes</TITLE>
</HEAD><BODY>
<H1>LWP::MediaTypes</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-07-18<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
LWP::MediaTypes - guess media type for a file or a URL
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use LWP::MediaTypes qw(guess_media_type);
$type = guess_media_type(&quot;/tmp/foo.gif&quot;);
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This module provides functions for handling media (also known as
<FONT SIZE="-1">MIME</FONT>) types and encodings. The mapping from file extensions to media
types is defined by the <I>media.types</I> file. If the <I>~/.media.types</I>
file exists it is used instead.
For backwards compatibility we will also look for <I>~/.mime.types</I>.
<P>
The following functions are exported by default:
<DL COMPACT>
<DT id="1">guess_media_type( $filename )<DD>
<DT id="2">guess_media_type( $uri )<DD>
<DT id="3">guess_media_type( $filename_or_object, $header_to_modify )<DD>
This function tries to guess media type and encoding for a file or objects that
support the a <TT>&quot;path&quot;</TT> or <TT>&quot;filename&quot;</TT> method, eg, <FONT SIZE="-1">URI</FONT> or File::Temp objects.
When an object does not support either method, it will be stringified to
determine the filename.
It returns the content type, which is a string like <TT>&quot;text/html&quot;</TT>.
In array context it also returns any content encodings applied (in the
order used to encode the file). You can pass a <FONT SIZE="-1">URI</FONT> object
reference, instead of the file name.
<P>
If the type can not be deduced from looking at the file name,
then <B>guess_media_type()</B> will let the <TT>&quot;-T&quot;</TT> Perl operator take a look.
If this works (and <TT>&quot;-T&quot;</TT> returns a <FONT SIZE="-1">TRUE</FONT> value) then we return
<I>text/plain</I> as the type, otherwise we return
<I>application/octet-stream</I> as the type.
<P>
The optional second argument should be a reference to a HTTP::Headers
object or any object that implements the <TT>$obj</TT>-&gt;header method in a
similar way. When it is present the values of the
'Content-Type' and 'Content-Encoding' will be set for this header.
<DT id="4">media_suffix( $type, ... )<DD>
This function will return all suffixes that can be used to denote the
specified media type(s). Wildcard types can be used. In a scalar
context it will return the first suffix found. Examples:
<P>
<PRE>
@suffixes = media_suffix('image/*', 'audio/basic');
$suffix = media_suffix('text/html');
</PRE>
</DL>
<P>
The following functions are only exported by explicit request:
<DL COMPACT>
<DT id="5">add_type( $type, @exts )<DD>
Associate a list of file extensions with the given media type.
Example:
<P>
<PRE>
add_type(&quot;x-world/x-vrml&quot; =&gt; qw(wrl vrml));
</PRE>
<DT id="6">add_encoding( $type, @ext )<DD>
Associate a list of file extensions with an encoding type.
Example:
<P>
<PRE>
add_encoding(&quot;x-gzip&quot; =&gt; &quot;gz&quot;);
</PRE>
<DT id="7">read_media_types( @files )<DD>
Parse media types files and add the type mappings found there.
Example:
<P>
<PRE>
read_media_types(&quot;conf/mime.types&quot;);
</PRE>
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright 1995-1999 Gisle Aas.
<P>
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="8"><A HREF="#lbAB">NAME</A><DD>
<DT id="9"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="10"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="11"><A HREF="#lbAE">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:47 GMT, March 31, 2021
</BODY>
</HTML>