205 lines
4.0 KiB
HTML
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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
LWP::MediaTypes - guess media type for a file or a URL
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
use LWP::MediaTypes qw(guess_media_type);
|
|
$type = guess_media_type("/tmp/foo.gif");
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAD"> </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>"path"</TT> or <TT>"filename"</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>"text/html"</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>"-T"</TT> Perl operator take a look.
|
|
If this works (and <TT>"-T"</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>->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("x-world/x-vrml" => 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("x-gzip" => "gz");
|
|
|
|
</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("conf/mime.types");
|
|
|
|
</PRE>
|
|
|
|
|
|
</DL>
|
|
<A NAME="lbAE"> </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"> </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>
|