Skip to content

Commit aff7519

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 71f6709 + d786894 commit aff7519

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<modelVersion>4.0.0</modelVersion>
1919
<artifactId>http-server</artifactId>
20-
<version>0.0.40</version>
20+
<version>0.0.41</version>
2121
<name>HttpServer</name>
2222
<packaging>jar</packaging>
2323

src/main/java/info/unterrainer/commons/httpserver/HandlerUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,25 @@ else if (mandatory)
143143
throw new BadRequestException(String.format("Parameter %s is mandatory", name));
144144
return result;
145145
}
146+
147+
public Boolean getQueryParamAsBoolean(final Context ctx, final String name) {
148+
return getQueryParamAsBoolean(ctx, name, true, null);
149+
}
150+
151+
public Boolean getQueryParamAsBoolean(final Context ctx, final String name, final Boolean defaultValue) {
152+
return getQueryParamAsBoolean(ctx, name, false, defaultValue);
153+
}
154+
155+
private Boolean getQueryParamAsBoolean(final Context ctx, final String name, final boolean mandatory,
156+
final Boolean defaultValue) {
157+
String o = ctx.queryParam(name);
158+
Boolean result = defaultValue;
159+
160+
if (o != null) {
161+
String v = o.strip().toLowerCase();
162+
return !v.equals("false") || !v.equals("no") || !v.equals("0");
163+
} else if (mandatory)
164+
throw new BadRequestException(String.format("Parameter %s is mandatory", name));
165+
return result;
166+
}
146167
}

0 commit comments

Comments
 (0)