1LWP::MediaTypes(3)    User Contributed Perl Documentation   LWP::MediaTypes(3)
2
3
4

NAME

6       LWP::MediaTypes - guess media type for a file or a URL
7

SYNOPSIS

9        use LWP::MediaTypes qw(guess_media_type);
10        $type = guess_media_type("/tmp/foo.gif");
11

DESCRIPTION

13       This module provides functions for handling media (also known as MIME)
14       types and encodings.  The mapping from file extensions to media types
15       is defined by the media.types file.  If the ~/.media.types file exists
16       it is used instead.  For backwards compatibility we will also look for
17       ~/.mime.types.
18
19       The following functions are exported by default:
20
21       guess_media_type( $filename )
22       guess_media_type( $uri )
23       guess_media_type( $filename_or_object, $header_to_modify )
24           This function tries to guess media type and encoding for a file or
25           objects that support the a "path" or "filename" method, eg, URI or
26           File::Temp objects.  When an object does not support either method,
27           it will be stringified to determine the filename.  It returns the
28           content type, which is a string like "text/html".  In array context
29           it also returns any content encodings applied (in the order used to
30           encode the file).  You can pass a URI object reference, instead of
31           the file name.
32
33           If the type can not be deduced from looking at the file name, then
34           guess_media_type() will let the "-T" Perl operator take a look.  If
35           this works (and "-T" returns a TRUE value) then we return
36           text/plain as the type, otherwise we return
37           application/octet-stream as the type.
38
39           The optional second argument should be a reference to a
40           HTTP::Headers object or any object that implements the $obj->header
41           method in a similar way.  When it is present the values of the
42           'Content-Type' and 'Content-Encoding' will be set for this header.
43
44       media_suffix( $type, ... )
45           This function will return all suffixes that can be used to denote
46           the specified media type(s).  Wildcard types can be used.  In a
47           scalar context it will return the first suffix found. Examples:
48
49             @suffixes = media_suffix('image/*', 'audio/basic');
50             $suffix = media_suffix('text/html');
51
52       The following functions are only exported by explicit request:
53
54       add_type( $type, @exts )
55           Associate a list of file extensions with the given media type.
56           Example:
57
58               add_type("x-world/x-vrml" => qw(wrl vrml));
59
60       add_encoding( $type, @ext )
61           Associate a list of file extensions with an encoding type.
62           Example:
63
64            add_encoding("x-gzip" => "gz");
65
66       read_media_types( @files )
67           Parse media types files and add the type mappings found there.
68           Example:
69
70               read_media_types("conf/mime.types");
71
73       Copyright 1995-1999 Gisle Aas.
74
75       This library is free software; you can redistribute it and/or modify it
76       under the same terms as Perl itself.
77
78
79
80perl v5.32.1                      2021-01-27                LWP::MediaTypes(3)
Impressum