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

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

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
public class HttpHeader {
26

27
    private String _label;
28
    private Map _properties;
29
    protected String _headerString;
30

31
    /**
32
     * construct a HttpHeader from the given headerString
33
     *
34
     * @param headerString
35
     */
36
    public HttpHeader(String headerString) {
37
        this(headerString, null);
1✔
38
    }
1✔
39

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

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

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

74
    protected String getProperty(String key) {
75
        return unQuote((String) getProperties().get(key));
1✔
76
    }
77

78
    private String unQuote(String value) {
79
        if (value == null || value.length() <= 1 || !value.startsWith("\"") || !value.endsWith("\"")) {
1!
80
            return value;
1✔
81
        }
82

83
        return value.substring(1, value.length() - 1);
1✔
84
    }
85

86
    // Headers have the general format (ignoring unquoted white space):
87
    // header ::= property-def | property-def ',' header
88
    // property-def ::= name '=' value
89
    // name ::= ID
90
    // value ::= ID | QUOTED-STRING
91
    //
92
    static private Map loadProperties(String parameterString) {
93
        Properties properties = new Properties();
1✔
94
        char[] chars = parameterString.toCharArray();
1✔
95
        int i = 0;
1✔
96
        StringBuilder sb = new StringBuilder();
1✔
97

98
        while (i < chars.length) {
1!
99
            while (i < chars.length && Character.isWhitespace(chars[i])) {
1!
100
                i++;
1✔
101
            }
102
            while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
1✔
103
                sb.append(chars[i]);
1✔
104
                i++;
1✔
105
            }
106
            String name = sb.toString();
1✔
107
            sb.setLength(0);
1✔
108
            while (i < chars.length && chars[i] != '=') {
1!
109
                i++;
×
110
            }
111
            if (i == chars.length) {
1✔
112
                break;
1✔
113
            }
114
            i++; // skip '='
1✔
115
            while (i < chars.length && Character.isWhitespace(chars[i])) {
1!
116
                i++;
×
117
            }
118
            if (i == chars.length) {
1!
119
                break;
×
120
            }
121
            if (chars[i] == '"') {
1!
122
                sb.append(chars[i]);
1✔
123
                i++;
1✔
124
                while (i < chars.length && chars[i] != '"') {
1!
125
                    sb.append(chars[i]);
1✔
126
                    i++;
1✔
127
                }
128
                sb.append('"');
1✔
129
                if (i < chars.length) {
1!
130
                    i++; // skip close quote
1✔
131
                }
132
            } else {
133
                while (i < chars.length && Character.isJavaIdentifierPart(chars[i])) {
×
134
                    sb.append(chars[i]);
×
135
                    i++;
×
136
                }
137
            }
138
            properties.setProperty(name, sb.toString());
1✔
139
            sb.setLength(0);
1✔
140
            while (i < chars.length && chars[i] != ',') {
1✔
141
                i++;
1✔
142
            }
143
            if (i == chars.length) {
1✔
144
                break;
1✔
145
            }
146
            i++; // skip '='
1✔
147
        }
1✔
148
        return properties;
1✔
149
    }
150

151
    public String getLabel() {
152
        return _label;
1✔
153
    }
154

155
    public Map getProperties() {
156
        return _properties;
1✔
157
    }
158
}
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