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.hc.core5.http.message; 29 30 import org.apache.hc.core5.http.HeaderElement; 31 import org.apache.hc.core5.http.NameValuePair; 32 import org.apache.hc.core5.util.CharArrayBuffer; 33 34 /** 35 * Interface for formatting elements of a header value. 36 * Instances of this interface are expected to be stateless and thread-safe. 37 * 38 * @since 4.0 39 */ 40 public interface HeaderValueFormatter { 41 42 /** 43 * Formats an array of header elements. 44 * 45 * @param buffer buffer to write formatted content to. 46 * @param elems the header elements to format 47 * @param quote {@code true} to always format with quoted values, 48 * {@code false} to use quotes only when necessary 49 */ 50 void formatElements(CharArrayBuffer buffer, HeaderElement[] elems, boolean quote); 51 52 /** 53 * Formats one header element. 54 * 55 * @param buffer buffer to write formatted content to. 56 * @param elem the header element to format 57 * @param quote {@code true} to always format with quoted values, 58 * {@code false} to use quotes only when necessary 59 */ 60 void formatHeaderElement(CharArrayBuffer buffer, HeaderElement elem, boolean quote); 61 62 /** 63 * Formats the parameters of a header element. 64 * That's a list of name-value pairs, to be separated by semicolons. 65 * This method will <i>not</i> generate a leading semicolon. 66 * 67 * @param buffer buffer to write formatted content to. 68 * @param nvps the parameters (name-value pairs) to format 69 * @param quote {@code true} to always format with quoted values, 70 * {@code false} to use quotes only when necessary 71 */ 72 void formatParameters(CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote); 73 74 /** 75 * Formats one name-value pair, where the value is optional. 76 * 77 * @param buffer buffer to write formatted content to. 78 * @param nvp the name-value pair to format 79 * @param quote {@code true} to always format with a quoted value, 80 * {@code false} to use quotes only when necessary 81 */ 82 void formatNameValuePair(CharArrayBuffer buffer, NameValuePair nvp, boolean quote); 83 84 } 85