~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/http/content_type.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: sligocki@google.com (Shawn Ligocki)
18
 
//
19
 
// A collection of content-types and their attributes.
20
 
 
21
 
#ifndef PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_
22
 
#define PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_
23
 
 
24
 
#include <set>
25
 
 
26
 
#include "pagespeed/kernel/base/string.h"
27
 
#include "pagespeed/kernel/base/string_util.h"
28
 
 
29
 
namespace net_instaweb {
30
 
 
31
 
struct ContentType {
32
 
 public:
33
 
  // The MIME types we process.
34
 
  enum Type {
35
 
    kHtml,
36
 
    kXhtml,
37
 
    kCeHtml,  // See http://en.wikipedia.org/wiki/CE-HTML
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,
53
 
    kOctetStream,  // Binary resources.
54
 
    kOther,  // Used to specify a new local ContentType in one test file.
55
 
  };
56
 
 
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();
61
 
 
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_; }
66
 
 
67
 
  // Return true iff this content type is CSS.
68
 
  bool IsCss() const;
69
 
 
70
 
  // Return true iff this content type is JS.
71
 
  bool IsJs() const;
72
 
 
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;
76
 
 
77
 
  // Return true iff this content type is XML of some kind (either XHTML or
78
 
  // some other XML).
79
 
  bool IsXmlLike() const;
80
 
 
81
 
  // Return true iff this content type is Flash.
82
 
  bool IsFlash() const;
83
 
 
84
 
  // Return true iff this content type is Image.
85
 
  bool IsImage() const;
86
 
 
87
 
  // Return true iff this content type is Video.
88
 
  bool IsVideo() const;
89
 
 
90
 
  // Return true iff this content type is Audio.
91
 
  bool IsAudio() const;
92
 
 
93
 
  // Heuristic to determine whether this should be treated as a static resource.
94
 
  bool IsLikelyStaticResource() const;
95
 
 
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"
101
 
  Type type_;
102
 
};
103
 
 
104
 
// HTML-like (i.e. rewritable) text:
105
 
extern const ContentType& kContentTypeHtml;
106
 
extern const ContentType& kContentTypeXhtml;
107
 
extern const ContentType& kContentTypeCeHtml;
108
 
// Other text:
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;
115
 
// Images:
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;
122
 
// PDF:
123
 
extern const ContentType& kContentTypePdf;
124
 
 
125
 
// Binary/octet-stream.
126
 
extern const ContentType& kContentTypeBinaryOctetStream;
127
 
 
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);
132
 
 
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);
141
 
 
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
144
 
// present.
145
 
void MimeTypeListToContentTypeSet(
146
 
    const GoogleString& in,
147
 
    std::set<const ContentType*>* out);
148
 
 
149
 
}  // namespace net_instaweb
150
 
 
151
 
#endif  // PAGESPEED_KERNEL_HTTP_CONTENT_TYPE_H_