1 /*
2 * Copyright (c) 2002-2026 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 * </p>
27 *
28 * @author Ronald Brill
29 */
30 public class HtmlUnitBrowserCompatCookieHeaderValueFormatter extends BasicHeaderValueFormatter {
31
32 /**
33 * Single instance as in BasicHeaderValueFormatter.
34 */
35 public static final HtmlUnitBrowserCompatCookieHeaderValueFormatter
36 INSTANCE = new HtmlUnitBrowserCompatCookieHeaderValueFormatter();
37
38 /**
39 * {@inheritDoc}
40 * Overwritten to disable automatic addition of quotes.
41 */
42 @Override
43 protected boolean isSeparator(final char ch) {
44 return false;
45 }
46
47 /**
48 * Looks like browsers are not doing any escaping.
49 * {@inheritDoc}
50 */
51 @Override
52 protected boolean isUnsafe(final char ch) {
53 return false;
54 }
55 }