Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
content_type.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
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
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
20 
21 #ifndef PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_
22 #define PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_
23 
24 #include <set>
25 
28 
29 namespace net_instaweb {
30 
31 struct ContentType {
32  public:
34  enum Type {
35  kHtml,
36  kXhtml,
38  kJavascript,
39  kCss,
40  kText,
41  kXml,
42  kPng,
43  kGif,
44  kJpeg,
45  kSwf,
46  kWebp,
47  kIco,
48  kJson,
49  kSourceMap,
50  kPdf,
51  kVideo,
52  kAudio,
55  };
56 
60  static int MaxProducedExtensionLength();
61 
62  const char* mime_type() const { return mime_type_; }
64  const char* file_extension() const { return file_extension_; }
65  Type type() const { return type_; }
66 
68  bool IsCss() const;
69 
71  bool IsJsLike() const;
72 
75  bool IsHtmlLike() const;
76 
79  bool IsXmlLike() const;
80 
82  bool IsFlash() const;
83 
85  bool IsImage() const;
86 
88  bool IsVideo() const;
89 
91  bool IsAudio() const;
92 
94  bool IsLikelyStaticResource() const;
95 
97  bool IsCompressible() const;
98 
102  const char* mime_type_;
103  const char* file_extension_;
104  Type type_;
105 };
106 
108 extern const ContentType& kContentTypeHtml;
109 extern const ContentType& kContentTypeXhtml;
110 extern const ContentType& kContentTypeCeHtml;
112 extern const ContentType& kContentTypeJavascript;
113 extern const ContentType& kContentTypeCss;
114 extern const ContentType& kContentTypeText;
115 extern const ContentType& kContentTypeXml;
116 extern const ContentType& kContentTypeJson;
117 extern const ContentType& kContentTypeSourceMap;
119 extern const ContentType& kContentTypePng;
120 extern const ContentType& kContentTypeGif;
121 extern const ContentType& kContentTypeJpeg;
122 extern const ContentType& kContentTypeSwf;
123 extern const ContentType& kContentTypeWebp;
124 extern const ContentType& kContentTypeIco;
126 extern const ContentType& kContentTypePdf;
127 
130 
133 const ContentType* NameExtensionToContentType(const StringPiece& name);
134 const ContentType* MimeTypeToContentType(const StringPiece& mime_type);
135 
141 bool ParseContentType(const StringPiece& content_type_str,
142  GoogleString* mime_type,
143  GoogleString* charset);
144 
149  const GoogleString& in,
150  std::set<const ContentType*>* out);
151 
152 }
153 
154 #endif
void MimeTypeListToContentTypeSet(const GoogleString &in, std::set< const ContentType * > *out)
bool IsJsLike() const
Return true iff this content type is JS, or something similar like JSON.
const ContentType & kContentTypeHtml
HTML-like (i.e. rewritable) text:
const char * mime_type_
Definition: content_type.h:102
bool IsLikelyStaticResource() const
Heuristic to determine whether this should be treated as a static resource.
const ContentType & kContentTypePng
Images:
bool IsCss() const
Return true iff this content type is CSS.
const ContentType * NameExtensionToContentType(const StringPiece &name)
const char * file_extension() const
Definition: content_type.h:64
Binary resources.
Definition: content_type.h:53
bool IsCompressible() const
Heuristic to determine whether compressing the resource is beneficial.
const char * file_extension_
includes ".", e.g. ".ext"
Definition: content_type.h:103
bool IsVideo() const
Return true iff this content type is Video.
bool ParseContentType(const StringPiece &content_type_str, GoogleString *mime_type, GoogleString *charset)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
See http://en.wikipedia.org/wiki/CE-HTML.
Definition: content_type.h:37
bool IsImage() const
Return true iff this content type is Image.
Type
The MIME types we process.
Definition: content_type.h:34
Used to specify a new local ContentType in one test file.
Definition: content_type.h:54
static int MaxProducedExtensionLength()
Definition: content_type.h:31
const ContentType & kContentTypeJavascript
Other text:
bool IsFlash() const
Return true iff this content type is Flash.
const ContentType & kContentTypePdf
PDF:
bool IsAudio() const
Return true iff this content type is Audio.
const ContentType & kContentTypeBinaryOctetStream
Binary/octet-stream.