Content-Type
HTTP header is the vehicle used to convey the MIME type to the browser. In Firefox if you right-click on this page is choose ‘View Page Info’, you will see that the Content-Type of this page is text/html
.Content-Type
to let the browser know what we were sending it. This may seem odd if you have worked with other web servers such as Apache. You may have used Apache to host lots of types of content and never had to set any MIME types. This is because Apache is doing all the MIME work for you. If you look in your Apache configuration directory, you will find a file called mime.types that contains entries that look like this:image/bmp bmp
image/gif gif
image/jpeg jpeg jpg jpe
...
Content-Type
setter for SQL Anywhere web services.First, we need a table to hold the extensions dictionary:CREATE TABLE MIMEType (
"Extension" CHAR(255) NOT NULL PRIMARY KEY,
"Type" CHAR(255) NOT NULL
);
CREATE PROCEDURE AutoSetMIMEType()
BEGIN
DECLARE loc INTEGER;
DECLARE ext CHAR(255);
DECLARE mimetype CHAR(255); -- Find the location of the last period in the URI
SET loc = LOCATE(HTTP_Header('@HttpURI'), '.', -1); -- If no period exists, default to ‘text/plain’
IF loc > 0 THEN
-- Extract the extension and convert to lower case
SET ext = LOWER(SUBSTR(HTTP_Header('@HttpURI'), loc + 1));
-- If the extension exists, use the corresponding type
-- Otherwise default to ‘text/plain’
IF EXISTS(SELECT Extension FROM MIMEType where Extension = ext) THEN
SELECT Type INTO mimetype FROM MIMEType where Extension = ext;
CALL sa_set_http_header('Content-Type', mimetype);
ELSE
CALL sa_set_http_header('Content-Type', 'text/plain');
END IF;
ELSE
CALL sa_set_http_header('Content-Type', 'text/plain');
END IF;
END;
INSERT INTO MIMEType VALUES('bmp', 'image/bmp');
INSERT INTO MIMEType VALUES('gif', 'image/gif');
INSERT INTO MIMEType VALUES('jpeg', 'image/jpeg');
INSERT INTO MIMEType VALUES('jpg', 'image/jpeg');
INSERT INTO MIMEType VALUES('jpe', 'image/jpeg');
...
CALL AutoSetMIMEType();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 |