1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.config;
29
30 import org.apache.http.util.Args;
31
32
33
34
35
36
37
38
39
40
41
42 public class MessageConstraints implements Cloneable {
43
44 public static final MessageConstraints DEFAULT = new Builder().build();
45
46 private final int maxLineLength;
47 private final int maxHeaderCount;
48
49 MessageConstraints(final int maxLineLength, final int maxHeaderCount) {
50 super();
51 this.maxLineLength = maxLineLength;
52 this.maxHeaderCount = maxHeaderCount;
53 }
54
55 public int getMaxLineLength() {
56 return maxLineLength;
57 }
58
59 public int getMaxHeaderCount() {
60 return maxHeaderCount;
61 }
62
63 @Override
64 protected MessageConstraints clone() throws CloneNotSupportedException {
65 return (MessageConstraints) super.clone();
66 }
67
68 @Override
69 public String toString() {
70 final StringBuilder builder = new StringBuilder();
71 builder.append("[maxLineLength=").append(maxLineLength)
72 .append(", maxHeaderCount=").append(maxHeaderCount)
73 .append("]");
74 return builder.toString();
75 }
76
77 public static MessageConstraints lineLen(final int max) {
78 return new MessageConstraints(Args.notNegative(max, "Max line length"), -1);
79 }
80
81 public static MessageConstraints.Builder custom() {
82 return new Builder();
83 }
84
85 public static MessageConstraints.Builder copy(final MessageConstraints config) {
86 Args.notNull(config, "Message constraints");
87 return new Builder()
88 .setMaxHeaderCount(config.getMaxHeaderCount())
89 .setMaxLineLength(config.getMaxLineLength());
90 }
91
92 public static class Builder {
93
94 private int maxLineLength;
95 private int maxHeaderCount;
96
97 Builder() {
98 this.maxLineLength = -1;
99 this.maxHeaderCount = -1;
100 }
101
102 public Builder setMaxLineLength(final int maxLineLength) {
103 this.maxLineLength = maxLineLength;
104 return this;
105 }
106
107 public Builder setMaxHeaderCount(final int maxHeaderCount) {
108 this.maxHeaderCount = maxHeaderCount;
109 return this;
110 }
111
112 public MessageConstraints build() {
113 return new MessageConstraints(maxLineLength, maxHeaderCount);
114 }
115
116 }
117
118 }