View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.impl.client;
29  
30  import org.apache.http.client.config.CookieSpecs;
31  import org.apache.http.config.Lookup;
32  import org.apache.http.config.RegistryBuilder;
33  import org.apache.http.conn.util.PublicSuffixMatcher;
34  import org.apache.http.conn.util.PublicSuffixMatcherLoader;
35  import org.apache.http.cookie.CookieSpecProvider;
36  import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
37  import org.apache.http.impl.cookie.IgnoreSpecProvider;
38  import org.apache.http.impl.cookie.NetscapeDraftSpecProvider;
39  import org.apache.http.impl.cookie.RFC6265CookieSpecProvider;
40  
41  /**
42   * @since 4.5
43   */
44  public final class CookieSpecRegistries {
45  
46      /**
47       * Creates a builder containing the default registry entries, using the provided public suffix matcher.
48       */
49      public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) {
50          final CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider(publicSuffixMatcher);
51          final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
52                  RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
53          final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
54                  RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
55          return RegistryBuilder.<CookieSpecProvider>create()
56                  .register(CookieSpecs.DEFAULT, defaultProvider)
57                  .register("best-match", defaultProvider)
58                  .register("compatibility", defaultProvider)
59                  .register(CookieSpecs.STANDARD, laxStandardProvider)
60                  .register(CookieSpecs.STANDARD_STRICT, strictStandardProvider)
61                  .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
62                  .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
63      }
64  
65      /**
66       * Creates a builder containing the default registry entries with the default public suffix matcher.
67       */
68      public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder() {
69          return createDefaultBuilder(PublicSuffixMatcherLoader.getDefault());
70      }
71  
72      /**
73       * Creates the default registry, using the default public suffix matcher.
74       */
75      public static Lookup<CookieSpecProvider> createDefault() {
76          return createDefault(PublicSuffixMatcherLoader.getDefault());
77      }
78  
79      /**
80       * Creates the default registry with the provided public suffix matcher
81       */
82      public static Lookup<CookieSpecProvider> createDefault(final PublicSuffixMatcher publicSuffixMatcher) {
83          return createDefaultBuilder(publicSuffixMatcher).build();
84      }
85  
86      private CookieSpecRegistries() {}
87  
88  }