Page Speed Optimization Libraries  1.3.25.1
net/instaweb/http/public/content_type.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00020 
00021 #ifndef NET_INSTAWEB_HTTP_PUBLIC_CONTENT_TYPE_H_
00022 #define NET_INSTAWEB_HTTP_PUBLIC_CONTENT_TYPE_H_
00023 
00024 #include <set>
00025 
00026 #include "net/instaweb/util/public/string.h"
00027 #include "net/instaweb/util/public/string_util.h"
00028 
00029 namespace net_instaweb {
00030 
00031 struct ContentType {
00032  public:
00034   enum Type {
00035     kHtml,
00036     kXhtml,
00037     kCeHtml,  
00038     kJavascript,
00039     kCss,
00040     kText,
00041     kXml,
00042     kPng,
00043     kGif,
00044     kJpeg,
00045     kSwf,
00046     kWebp,
00047     kIco,
00048     kJson,
00049     kPdf,
00050     kVideo,
00051     kOctetStream,  
00052     kOther,  
00053   };
00054 
00058   static int MaxProducedExtensionLength();
00059 
00060   const char* mime_type() const { return mime_type_; }
00062   const char* file_extension() const { return file_extension_; }
00063   Type type() const { return type_; }
00064 
00066   bool IsCss() const;
00067 
00070   bool IsHtmlLike() const;
00071 
00074   bool IsXmlLike() const;
00075 
00077   bool IsFlash() const;
00078 
00080   bool IsImage() const;
00081 
00083   bool IsVideo() const;
00084 
00088   const char* mime_type_;
00089   const char* file_extension_; 
00090   Type type_;
00091 };
00092 
00094 extern const ContentType& kContentTypeHtml;
00095 extern const ContentType& kContentTypeXhtml;
00096 extern const ContentType& kContentTypeCeHtml;
00098 extern const ContentType& kContentTypeJavascript;
00099 extern const ContentType& kContentTypeCss;
00100 extern const ContentType& kContentTypeText;
00101 extern const ContentType& kContentTypeXml;
00102 extern const ContentType& kContentTypeJson;
00104 extern const ContentType& kContentTypePng;
00105 extern const ContentType& kContentTypeGif;
00106 extern const ContentType& kContentTypeJpeg;
00107 extern const ContentType& kContentTypeSwf;
00108 extern const ContentType& kContentTypeWebp;
00109 extern const ContentType& kContentTypeIco;
00111 extern const ContentType& kContentTypePdf;
00112 
00114 extern const ContentType& kContentTypeBinaryOctetStream;
00115 
00118 const ContentType* NameExtensionToContentType(const StringPiece& name);
00119 const ContentType* MimeTypeToContentType(const StringPiece& mime_type);
00120 
00126 bool ParseContentType(const StringPiece& content_type_str,
00127                       GoogleString* mime_type,
00128                       GoogleString* charset);
00129 
00133 void MimeTypeListToContentTypeSet(
00134     const GoogleString& in,
00135     std::set<const ContentType*>* out);
00136 
00137 }  
00138 
00139 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_CONTENT_TYPE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines