• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.05
/src/main/java/com/meterware/httpunit/HttpHeader.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import java.util.Map;
23
import java.util.Properties;
24

25
/**
26
 * The Class HttpHeader.
27
 */
28
public class HttpHeader {
29

30
    /** The label. */
31
    private String _label;
32

33
    /** The properties. */
34
    private Map _properties;
35

36
    /** The header string. */
37
    protected String _headerString;
38

39
    /**
40
     * construct a HttpHeader from the given headerString.
41
     *
42
     * @param headerString
43
     *            the header string
44
     */
45
    public HttpHeader(String headerString) {
46
        this(headerString, null);
1✔
47
    }
1✔
48

49
    /**
50
     * construct a HttpHeader from the given headerString and label.
51
     *
52
     * @param headerString
53
     *            the header string
54
     * @param defaultLabel
55
     *            the default label
56
     */
57
    public HttpHeader(String headerString, String defaultLabel) {
1✔
58
        if (headerString != null) {
1✔
59
            _headerString = headerString;
1✔
60
            final int index = headerString.indexOf(' ');
1✔
61
            if (index < 0) { // non-conforming header
1✔
62
                _label = defaultLabel;
1✔
63
                _properties = loadProperties(headerString);
1✔
64
            } else {
65
                _label = headerString.substring(0, index);
1✔
66
                _properties = loadProperties(headerString.substring(index + 1));
1✔
67
            }
68
        }
69
    }
1✔
70

71
    @Override
72
    public boolean equals(Object obj) {
73
        if (!getClass().equals(obj.getClass())) {
1!
74
            return false;
×
75
        }
76
        return getLabel().equals(((HttpHeader) obj).getLabel())
1!
77
                && getProperties().equals(((HttpHeader) obj).getProperties());
1!
78
    }
79

80
    @Override
81
    public String toString() {
82
        return getLabel() + " " + getProperties();
×
83
    }
84

85
    /**
86
     * Gets the property.
87
     *
88
     * @param key
89
     *            the key
90
     *
91
     * @return the property
92
     */
93
    protected String getProperty(String key) {
94
        return unQuote((String) getProperties().get(key));
1✔
95
    }
96

97
    /**
98
     * Un quote.
99
     *
100
     * @param value
101
     *            the value
102
     *
103
     * @return the string
104
     */
105
    private String unQuote(String value) {
106
        if (value == null || value.length() <= 1 || !value.startsWith("\"") || !value.endsWith("\"")) {
1!
107
            return value;
1✔
108
        }
109

110
        return value.substring(1, value.length() - 1);
1✔
111
    }
112

113
    // Headers have the general format (ignoring unquoted white space):
114
    // header ::= property-def | property-def ',' header
115
    // property-def ::= name '=' value
116
    // name ::= ID
117
    // value ::= ID | QUOTED-STRING
118
    /**
119
     * Load properties.
120
     *
121
     * @param parameterString
122
     *            the parameter string
123
     *
124
     * @return the map
125
     */
126
    //
127
    static private Map loadProperties(String parameterString) {
128
        Properties properties = new Properties();
1✔
129
        char[] chars = parameterString.toCharArray();
1✔
130
        int i = 0;
1✔
131
        StringBuilder sb = new StringBuilder();
1✔
132

133
        while (i < chars.length) {
1!
134
            while (i < chars.length && Character.isWhitespace(chars[i])) {
1!
135
                i++;
1✔
136
            }
137
            while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
1✔
138
                sb.append(chars[i]);
1✔
139
                i++;
1✔
140
            }
141
            String name = sb.toString();
1✔
142
            sb.setLength(0);
1✔
143
            while (i < chars.length && chars[i] != '=') {
1!
144
                i++;
×
145
            }
146
            if (i == chars.length) {
1✔
147
                break;
1✔
148
            }
149
            i++; // skip '='
1✔
150
            while (i < chars.length && Character.isWhitespace(chars[i])) {
1!
151
                i++;
×
152
            }
153
            if (i == chars.length) {
1!
154
                break;
×
155
            }
156
            if (chars[i] == '"') {
1!
157
                sb.append(chars[i]);
1✔
158
                i++;
1✔
159
                while (i < chars.length && chars[i] != '"') {
1!
160
                    sb.append(chars[i]);
1✔
161
                    i++;
1✔
162
                }
163
                sb.append('"');
1✔
164
                if (i < chars.length) {
1!
165
                    i++; // skip close quote
1✔
166
                }
167
            } else {
168
                while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
×
169
                    sb.append(chars[i]);
×
170
                    i++;
×
171
                }
172
            }
173
            properties.setProperty(name, sb.toString());
1✔
174
            sb.setLength(0);
1✔
175
            while (i < chars.length && chars[i] != ',') {
1✔
176
                i++;
1✔
177
            }
178
            if (i == chars.length) {
1✔
179
                break;
1✔
180
            }
181
            i++; // skip '='
1✔
182
        }
1✔
183
        return properties;
1✔
184
    }
185

186
    /**
187
     * Gets the label.
188
     *
189
     * @return the label
190
     */
191
    public String getLabel() {
192
        return _label;
1✔
193
    }
194

195
    /**
196
     * Gets the properties.
197
     *
198
     * @return the properties
199
     */
200
    public Map getProperties() {
201
        return _properties;
1✔
202
    }
203
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc