Skip to content

Commit

Permalink
yegor256#336 better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Jun 8, 2015
1 parent 51aa5b8 commit bb81698
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/main/java/org/takes/rs/RsPrint.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,29 @@ public void print(final OutputStream output) throws IOException {
public void printHead(final OutputStream output) throws IOException {
final String eol = "\r\n";
final Writer writer = new OutputStreamWriter(output);
boolean first = true;
int pos = 0;
for (final String line : this.head()) {
if (first) {
if (!RsPrint.FIRST.matcher(line).matches()) {
throw new IllegalArgumentException(
String.format(
// @checkstyle LineLength (1 line)
"first line of HTTP response \"%s\" doesn't match \"%s\" regular expression, but it should, according to RFC 7230",
line, RsPrint.FIRST
)
);
}
first = false;
} else if (!RsPrint.OTHERS.matcher(line).matches()) {
if (pos == 0 && !RsPrint.FIRST.matcher(line).matches()) {
throw new IllegalArgumentException(
String.format(
// @checkstyle LineLength (1 line)
"first line of HTTP response \"%s\" doesn't match \"%s\" regular expression, but it should, according to RFC 7230",
line, RsPrint.FIRST
)
);
}
if (pos > 0 && !RsPrint.OTHERS.matcher(line).matches()) {
throw new IllegalArgumentException(
String.format(
// @checkstyle LineLength (1 line)
"header line of HTTP response \"%s\" doesn't match \"%s\" regular expression, but it should, according to RFC 7230",
line, RsPrint.OTHERS
"header line #%d of HTTP response \"%s\" doesn't match \"%s\" regular expression, but it should, according to RFC 7230",
pos + 1, line, RsPrint.OTHERS
)
);
}
writer.append(line);
writer.append(eol);
++pos;
}
writer.append(eol);
writer.flush();
Expand Down

0 comments on commit bb81698

Please sign in to comment.