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 public class MessageConstraints implements Cloneable {
38
39 public static final MessageConstraints DEFAULT = new Builder().build();
40
41 private final int maxLineLength;
42 private final int maxHeaderCount;
43
44 MessageConstraints(final int maxLineLength, final int maxHeaderCount) {
45 super();
46 this.maxLineLength = maxLineLength;
47 this.maxHeaderCount = maxHeaderCount;
48 }
49
50 public int getMaxLineLength() {
51 return maxLineLength;
52 }
53
54 public int getMaxHeaderCount() {
55 return maxHeaderCount;
56 }
57
58 @Override
59 protected MessageConstraints clone() throws CloneNotSupportedException {
60 return (MessageConstraints) super.clone();
61 }
62
63 @Override
64 public String toString() {
65 final StringBuilder builder = new StringBuilder();
66 builder.append("[maxLineLength=").append(maxLineLength)
67 .append(", maxHeaderCount=").append(maxHeaderCount)
68 .append("]");
69 return builder.toString();
70 }
71
72 public static MessageConstraints lineLen(final int max) {
73 return new MessageConstraints(Args.notNegative(max, "Max line length"), -1);
74 }
75
76 public static MessageConstraints.Builder custom() {
77 return new Builder();
78 }
79
80 public static MessageConstraints.Builder copy(final MessageConstraints config) {
81 Args.notNull(config, "Message constraints");
82 return new Builder()
83 .setMaxHeaderCount(config.getMaxHeaderCount())
84 .setMaxLineLength(config.getMaxLineLength());
85 }
86
87 public static class Builder {
88
89 private int maxLineLength;
90 private int maxHeaderCount;
91
92 Builder() {
93 this.maxLineLength = -1;
94 this.maxHeaderCount = -1;
95 }
96
97 public Builder setMaxLineLength(final int maxLineLength) {
98 this.maxLineLength = maxLineLength;
99 return this;
100 }
101
102 public Builder setMaxHeaderCount(final int maxHeaderCount) {
103 this.maxHeaderCount = maxHeaderCount;
104 return this;
105 }
106
107 public MessageConstraints build() {
108 return new MessageConstraints(maxLineLength, maxHeaderCount);
109 }
110
111 }
112
113 }