1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software 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 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.httpclient;
16
17 import org.apache.http.message.BasicHeaderValueFormatter;
18
19 /**
20 * Customized BasicHeaderValueFormatter for HtmlUnit.
21 * <p>
22 * We use our own class because browsers do not automatically quote version1 cookies
23 * if the value contains special chars.
24 * I guess this is something special for HttpClient because HttpClient also removes
25 * the quotes from cookies (@see {@link HtmlUnitBrowserCompatCookieSpec})
26 *
27 * @author Ronald Brill
28 */
29 public class HtmlUnitBrowserCompatCookieHeaderValueFormatter extends BasicHeaderValueFormatter {
30
31 /**
32 * Single instance as in BasicHeaderValueFormatter.
33 */
34 public static final HtmlUnitBrowserCompatCookieHeaderValueFormatter
35 INSTANCE = new HtmlUnitBrowserCompatCookieHeaderValueFormatter();
36
37 /**
38 * {@inheritDoc}
39 * Overwritten to disable automatic addition of quotes.
40 */
41 @Override
42 protected boolean isSeparator(final char ch) {
43 return false;
44 }
45
46 /**
47 * Looks like browsers are not doing any escaping.
48 * {@inheritDoc}
49 */
50 @Override
51 protected boolean isUnsafe(final char ch) {
52 return false;
53 }
54 }