Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

lwp::mediatypes(3) [redhat man page]

LWP::MediaTypes(3)					User Contributed Perl Documentation					LWP::MediaTypes(3)

NAME
LWP::MediaTypes - guess media type for a file or a URL SYNOPSIS
use LWP::MediaTypes qw(guess_media_type); $type = guess_media_type("/tmp/foo.gif"); DESCRIPTION
This module provides functions for handling media (also known as MIME) types and encodings. The mapping from file extentions to media types is defined by the media.types file. If the ~/.media.types file exists it is used instead. For backwards compatability we will also look for ~/.mime.types. The following functions are exported by default: guess_media_type($filename_or_url, [$header_to_modify]) This function tries to guess media type and encoding for a file or url. It returns the content-type, which is a string like "text/html". In array context it also returns any content-encodings applied (in the order used to encode the file). You can pass a URI object reference, instead of the file name. If the type can not be deduced from looking at the file name, then guess_media_type() will let the "-T" Perl operator take a look. If this works (and "-T" returns a TRUE value) then we return text/plain as the type, otherwise we return application/octet-stream as the type. The optional second argument should be a reference to a HTTP::Headers object or any object that implements the $obj->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. media_suffix($type,...) 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: @suffixes = media_suffix('image/*', 'audio/basic'); $suffix = media_suffix('text/html'); The following functions are only exported by explict request: add_type($type, @exts) Associate a list of file extensions with the given media type. Example: add_type("x-world/x-vrml" => qw(wrl vrml)); add_encoding($type, @ext) Associate a list of file extensions with an encoding type. Example: add_encoding("x-gzip" => "gz"); read_media_types(@files) Parse media types files and add the type mappings found there. Example: read_media_types("conf/mime.types"); COPYRIGHT
Copyright 1995-1999 Gisle Aas. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. libwww-perl-5.65 1999-11-16 LWP::MediaTypes(3)

Check Out this Related Man Page

HTTP::Request::Common(3)				User Contributed Perl Documentation				  HTTP::Request::Common(3)

NAME
HTTP::Request::Common - Construct common HTTP::Request objects SYNOPSIS
use HTTP::Request::Common; $ua = LWP::UserAgent->new; $ua->request(GET 'http://www.sn.no/'); $ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]); DESCRIPTION
This module provide functions that return newly created "HTTP::Request" objects. These functions are usually more convenient to use than the standard "HTTP::Request" constructor for the most common requests. The following functions are provided: GET $url GET $url, Header => Value,... The GET() function returns an "HTTP::Request" object initialized with the "GET" method and the specified URL. It is roughly equivalent to the following call HTTP::Request->new( GET => $url, HTTP::Headers->new(Header => Value,...), ) but is less cluttered. What is different is that a header named "Content" will initialize the content part of the request instead of setting a header field. Note that GET requests should normally not have a content, so this hack makes more sense for the PUT() and POST() functions described below. The get(...) method of "LWP::UserAgent" exists as a shortcut for $ua->request(GET ...). HEAD $url HEAD $url, Header => Value,... Like GET() but the method in the request is "HEAD". The head(...) method of "LWP::UserAgent" exists as a shortcut for $ua->request(HEAD ...). PUT $url PUT $url, Header => Value,... PUT $url, Header => Value,..., Content => $content Like GET() but the method in the request is "PUT". The content of the request can be specified using the "Content" pseudo-header. This steals a bit of the header field namespace as there is no way to directly specify a header that is actually called "Content". If you really need this you must update the request returned in a separate statement. DELETE $url DELETE $url, Header => Value,... Like GET() but the method in the request is "DELETE". This function is not exported by default. POST $url POST $url, Header => Value,... POST $url, $form_ref, Header => Value,... POST $url, Header => Value,..., Content => $form_ref POST $url, Header => Value,..., Content => $content This works mostly like PUT() with "POST" as the method, but this function also takes a second optional array or hash reference parameter $form_ref. As for PUT() the content can also be specified directly using the "Content" pseudo-header, and you may also provide the $form_ref this way. The $form_ref argument can be used to pass key/value pairs for the form content. By default we will initialize a request using the "application/x-www-form-urlencoded" content type. This means that you can emulate an HTML <form> POSTing like this: POST 'http://www.perl.org/survey.cgi', [ name => 'Gisle Aas', email => 'gisle@aas.no', gender => 'M', born => '1964', perc => '3%', ]; This will create an HTTP::Request object that looks like this: POST http://www.perl.org/survey.cgi Content-Length: 66 Content-Type: application/x-www-form-urlencoded name=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25 Multivalued form fields can be specified by either repeating the field name or by passing the value as an array reference. The POST method also supports the "multipart/form-data" content used for Form-based File Upload as specified in RFC 1867. You trigger this content format by specifying a content type of 'form-data' as one of the request headers. If one of the values in the $form_ref is an array reference, then it is treated as a file part specification with the following interpretation: [ $file, $filename, Header => Value... ] [ undef, $filename, Header => Value,..., Content => $content ] The first value in the array ($file) is the name of a file to open. This file will be read and its content placed in the request. The routine will croak if the file can't be opened. Use an "undef" as $file value if you want to specify the content directly with a "Content" header. The $filename is the filename to report in the request. If this value is undefined, then the basename of the $file will be used. You can specify an empty string as $filename if you want to suppress sending the filename when you provide a $file value. If a $file is provided by no "Content-Type" header, then "Content-Type" and "Content-Encoding" will be filled in automatically with the values returned by LWP::MediaTypes::guess_media_type() Sending my ~/.profile to the survey used as example above can be achieved by this: POST 'http://www.perl.org/survey.cgi', Content_Type => 'form-data', Content => [ name => 'Gisle Aas', email => 'gisle@aas.no', gender => 'M', born => '1964', init => ["$ENV{HOME}/.profile"], ] This will create an HTTP::Request object that almost looks this (the boundary and the content of your ~/.profile is likely to be different): POST http://www.perl.org/survey.cgi Content-Length: 388 Content-Type: multipart/form-data; boundary="6G+f" --6G+f Content-Disposition: form-data; name="name" Gisle Aas --6G+f Content-Disposition: form-data; name="email" gisle@aas.no --6G+f Content-Disposition: form-data; name="gender" M --6G+f Content-Disposition: form-data; name="born" 1964 --6G+f Content-Disposition: form-data; name="init"; filename=".profile" Content-Type: text/plain PATH=/local/perl/bin:$PATH export PATH --6G+f-- If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE value, then you get back a request object with a subroutine closure as the content attribute. This subroutine will read the content of any files on demand and return it in suitable chunks. This allow you to upload arbitrary big files without using lots of memory. You can even upload infinite files like /dev/audio if you wish; however, if the file is not a plain file, there will be no Content-Length header defined for the request. Not all servers (or server applications) like this. Also, if the file(s) change in size between the time the Content-Length is calculated and the time that the last chunk is delivered, the subroutine will "Croak". The post(...) method of "LWP::UserAgent" exists as a shortcut for $ua->request(POST ...). SEE ALSO
HTTP::Request, LWP::UserAgent COPYRIGHT
Copyright 1997-2004, Gisle Aas This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2012-09-30 HTTP::Request::Common(3)
Man Page