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

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

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
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit;
9

10
import java.util.Map;
11
import java.util.Properties;
12

13
/**
14
 * The Class HttpHeader.
15
 */
16
public class HttpHeader {
17

18
    /** The label. */
19
    private String _label;
20

21
    /** The properties. */
22
    private Map _properties;
23

24
    /** The header string. */
25
    protected String _headerString;
26

27
    /**
28
     * construct a HttpHeader from the given headerString.
29
     *
30
     * @param headerString
31
     *            the header string
32
     */
33
    public HttpHeader(String headerString) {
34
        this(headerString, null);
1✔
35
    }
1✔
36

37
    /**
38
     * construct a HttpHeader from the given headerString and label.
39
     *
40
     * @param headerString
41
     *            the header string
42
     * @param defaultLabel
43
     *            the default label
44
     */
45
    public HttpHeader(String headerString, String defaultLabel) {
1✔
46
        if (headerString != null) {
1✔
47
            _headerString = headerString;
1✔
48
            final int index = headerString.indexOf(' ');
1✔
49
            if (index < 0) { // non-conforming header
1✔
50
                _label = defaultLabel;
1✔
51
                _properties = loadProperties(headerString);
1✔
52
            } else {
53
                _label = headerString.substring(0, index);
1✔
54
                _properties = loadProperties(headerString.substring(index + 1));
1✔
55
            }
56
        }
57
    }
1✔
58

59
    @Override
60
    public boolean equals(Object obj) {
61
        if (!getClass().equals(obj.getClass())) {
1!
62
            return false;
×
63
        }
64
        return getLabel().equals(((HttpHeader) obj).getLabel())
1!
65
                && getProperties().equals(((HttpHeader) obj).getProperties());
1!
66
    }
67

68
    @Override
69
    public String toString() {
70
        return getLabel() + " " + getProperties();
×
71
    }
72

73
    /**
74
     * Gets the property.
75
     *
76
     * @param key
77
     *            the key
78
     *
79
     * @return the property
80
     */
81
    protected String getProperty(String key) {
82
        return unQuote((String) getProperties().get(key));
1✔
83
    }
84

85
    /**
86
     * Un quote.
87
     *
88
     * @param value
89
     *            the value
90
     *
91
     * @return the string
92
     */
93
    private String unQuote(String value) {
94
        if (value == null || value.length() <= 1 || !value.startsWith("\"") || !value.endsWith("\"")) {
1!
95
            return value;
1✔
96
        }
97

98
        return value.substring(1, value.length() - 1);
1✔
99
    }
100

101
    // Headers have the general format (ignoring unquoted white space):
102
    // header ::= property-def | property-def ',' header
103
    // property-def ::= name '=' value
104
    // name ::= ID
105
    // value ::= ID | QUOTED-STRING
106
    /**
107
     * Load properties.
108
     *
109
     * @param parameterString
110
     *            the parameter string
111
     *
112
     * @return the map
113
     */
114
    //
115
    static private Map loadProperties(String parameterString) {
116
        Properties properties = new Properties();
1✔
117
        char[] chars = parameterString.toCharArray();
1✔
118
        int i = 0;
1✔
119
        StringBuilder sb = new StringBuilder();
1✔
120

121
        while (i < chars.length) {
1!
122
            while (i < chars.length && Character.isWhitespace(chars[i])) {
1!
123
                i++;
1✔
124
            }
125
            while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
1✔
126
                sb.append(chars[i]);
1✔
127
                i++;
1✔
128
            }
129
            String name = sb.toString();
1✔
130
            sb.setLength(0);
1✔
131
            while (i < chars.length && chars[i] != '=') {
1!
132
                i++;
×
133
            }
134
            if (i == chars.length) {
1✔
135
                break;
1✔
136
            }
137
            i++; // skip '='
1✔
138
            while (i < chars.length && Character.isWhitespace(chars[i])) {
1!
139
                i++;
×
140
            }
141
            if (i == chars.length) {
1!
142
                break;
×
143
            }
144
            if (chars[i] == '"') {
1!
145
                sb.append(chars[i]);
1✔
146
                i++;
1✔
147
                while (i < chars.length && chars[i] != '"') {
1!
148
                    sb.append(chars[i]);
1✔
149
                    i++;
1✔
150
                }
151
                sb.append('"');
1✔
152
                if (i < chars.length) {
1!
153
                    i++; // skip close quote
1✔
154
                }
155
            } else {
156
                while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
×
157
                    sb.append(chars[i]);
×
158
                    i++;
×
159
                }
160
            }
161
            properties.setProperty(name, sb.toString());
1✔
162
            sb.setLength(0);
1✔
163
            while (i < chars.length && chars[i] != ',') {
1✔
164
                i++;
1✔
165
            }
166
            if (i == chars.length) {
1✔
167
                break;
1✔
168
            }
169
            i++; // skip '='
1✔
170
        }
1✔
171
        return properties;
1✔
172
    }
173

174
    /**
175
     * Gets the label.
176
     *
177
     * @return the label
178
     */
179
    public String getLabel() {
180
        return _label;
1✔
181
    }
182

183
    /**
184
     * Gets the properties.
185
     *
186
     * @return the properties
187
     */
188
    public Map getProperties() {
189
        return _properties;
1✔
190
    }
191
}
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