2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: sligocki@google.com (Shawn Ligocki)
19
// A collection of content-types and their attributes.
21
#ifndef PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_
22
#define PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_
26
#include "pagespeed/kernel/base/string.h"
27
#include "pagespeed/kernel/base/string_util.h"
29
namespace net_instaweb {
33
// The MIME types we process.
37
kCeHtml, // See http://en.wikipedia.org/wiki/CE-HTML
53
kOctetStream, // Binary resources.
54
kOther, // Used to specify a new local ContentType in one test file.
57
// Returns the maximum extension length of any resource types our filters
58
// can create. Does not count the ".".
59
// See RewriteDriver::CreateOutputResourceWithPath()
60
static int MaxProducedExtensionLength();
62
const char* mime_type() const { return mime_type_; }
63
// TODO(sligocki): Stop returning '.' in file_extension().
64
const char* file_extension() const { return file_extension_; }
65
Type type() const { return type_; }
67
// Return true iff this content type is CSS.
70
// Return true iff this content type is JS.
73
// Return true iff this content type is HTML, or XHTML, or some other such
74
// thing (e.g. CE-HTML) that we can rewrite.
75
bool IsHtmlLike() const;
77
// Return true iff this content type is XML of some kind (either XHTML or
79
bool IsXmlLike() const;
81
// Return true iff this content type is Flash.
84
// Return true iff this content type is Image.
87
// Return true iff this content type is Video.
90
// Return true iff this content type is Audio.
93
// Heuristic to determine whether this should be treated as a static resource.
94
bool IsLikelyStaticResource() const;
96
// These fields should be private; we leave them public only so we can use
97
// struct literals in content_type.cc. Other code should use the above
98
// accessor methods instead of accessing these fields directly.
99
const char* mime_type_;
100
const char* file_extension_; // includes ".", e.g. ".ext"
104
// HTML-like (i.e. rewritable) text:
105
extern const ContentType& kContentTypeHtml;
106
extern const ContentType& kContentTypeXhtml;
107
extern const ContentType& kContentTypeCeHtml;
109
extern const ContentType& kContentTypeJavascript;
110
extern const ContentType& kContentTypeCss;
111
extern const ContentType& kContentTypeText;
112
extern const ContentType& kContentTypeXml;
113
extern const ContentType& kContentTypeJson;
114
extern const ContentType& kContentTypeSourceMap;
116
extern const ContentType& kContentTypePng;
117
extern const ContentType& kContentTypeGif;
118
extern const ContentType& kContentTypeJpeg;
119
extern const ContentType& kContentTypeSwf;
120
extern const ContentType& kContentTypeWebp;
121
extern const ContentType& kContentTypeIco;
123
extern const ContentType& kContentTypePdf;
125
// Binary/octet-stream.
126
extern const ContentType& kContentTypeBinaryOctetStream;
128
// Given a name (file or url), see if it has the canonical extension
129
// corresponding to a particular content type.
130
const ContentType* NameExtensionToContentType(const StringPiece& name);
131
const ContentType* MimeTypeToContentType(const StringPiece& mime_type);
133
// Extracts mime_type and charset from a string of the form
134
// "<mime_type>; charset=<charset>".
135
// If mime_type or charset is not specified, they will be populated
136
// with the empty string.
137
// Returns true if either a mime_type or a charset was extracted.
138
bool ParseContentType(const StringPiece& content_type_str,
139
GoogleString* mime_type,
140
GoogleString* charset);
142
// Splits comma-separated string to elements and tries to match each one with
143
// a recognized content type. The out set will be cleared first and must be
145
void MimeTypeListToContentTypeSet(
146
const GoogleString& in,
147
std::set<const ContentType*>* out);
149
} // namespace net_instaweb
151
#endif // PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_