00001 /* 00002 * Copyright 2011 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 00018 00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_TEST_URL_NAMER_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_TEST_URL_NAMER_H_ 00021 00022 #include "net/instaweb/rewriter/public/url_namer.h" 00023 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/string.h" 00026 #include "net/instaweb/util/public/string_util.h" 00027 00028 namespace net_instaweb { 00029 00030 class GoogleUrl; 00031 class OutputResource; 00032 class ResourceNamer; 00033 class RewriteOptions; 00034 00037 class TestUrlNamer : public UrlNamer { 00038 public: 00039 TestUrlNamer(); 00040 virtual ~TestUrlNamer(); 00041 00042 virtual GoogleString Encode(const RewriteOptions* rewrite_options, 00043 const OutputResource& output_resource) const; 00044 00045 virtual bool Decode(const GoogleUrl& request_url, 00046 GoogleUrl* owner_domain, 00047 GoogleString* decoded) const; 00048 00049 static GoogleString EncodeUrl(const StringPiece& original_base, 00050 const StringPiece& unmapped_base, 00051 const StringPiece& resolved_path, 00052 const ResourceNamer& leaf_details); 00053 00056 virtual bool ProxyMode() const { return proxy_mode_; } 00057 00059 virtual bool IsProxyEncoded(const GoogleUrl& url) const; 00060 00062 static void SetProxyMode(bool value) { proxy_mode_ = value; } 00063 00066 static void UseNormalEncoding(bool yes) { 00067 use_normal_encoding_ = yes; 00068 } 00069 00070 static bool UseNormalEncoding() { return use_normal_encoding_; } 00071 00072 private: 00073 bool IsOriginEncoded(const GoogleUrl& url) const; 00074 bool IsPathEncoded(const GoogleUrl& url) const; 00075 00076 static bool use_normal_encoding_; 00077 static bool proxy_mode_; 00078 00079 DISALLOW_COPY_AND_ASSIGN(TestUrlNamer); 00080 }; 00081 00082 } 00083 00084 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_TEST_URL_NAMER_H_