001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.impl.client; 029 030import org.apache.http.client.config.CookieSpecs; 031import org.apache.http.config.Lookup; 032import org.apache.http.config.RegistryBuilder; 033import org.apache.http.conn.util.PublicSuffixMatcher; 034import org.apache.http.conn.util.PublicSuffixMatcherLoader; 035import org.apache.http.cookie.CookieSpecProvider; 036import org.apache.http.impl.cookie.DefaultCookieSpecProvider; 037import org.apache.http.impl.cookie.IgnoreSpecProvider; 038import org.apache.http.impl.cookie.NetscapeDraftSpecProvider; 039import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; 040 041/** 042 * @since 4.5 043 */ 044public final class CookieSpecRegistries { 045 046 /** 047 * Creates a builder containing the default registry entries, using the provided public suffix matcher. 048 */ 049 public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) { 050 final CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider(publicSuffixMatcher); 051 final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider( 052 RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher); 053 final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider( 054 RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher); 055 return RegistryBuilder.<CookieSpecProvider>create() 056 .register(CookieSpecs.DEFAULT, defaultProvider) 057 .register("best-match", defaultProvider) 058 .register("compatibility", defaultProvider) 059 .register(CookieSpecs.STANDARD, laxStandardProvider) 060 .register(CookieSpecs.STANDARD_STRICT, strictStandardProvider) 061 .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider()) 062 .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider()); 063 } 064 065 /** 066 * Creates a builder containing the default registry entries with the default public suffix matcher. 067 */ 068 public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder() { 069 return createDefaultBuilder(PublicSuffixMatcherLoader.getDefault()); 070 } 071 072 /** 073 * Creates the default registry, using the default public suffix matcher. 074 */ 075 public static Lookup<CookieSpecProvider> createDefault() { 076 return createDefault(PublicSuffixMatcherLoader.getDefault()); 077 } 078 079 /** 080 * Creates the default registry with the provided public suffix matcher 081 */ 082 public static Lookup<CookieSpecProvider> createDefault(final PublicSuffixMatcher publicSuffixMatcher) { 083 return createDefaultBuilder(publicSuffixMatcher).build(); 084 } 085 086 private CookieSpecRegistries() {} 087 088}