本文整理汇总了Java中org.takes.rs.RsWithHeaders类的典型用法代码示例。如果您正苦于以下问题:Java RsWithHeaders类的具体用法?Java RsWithHeaders怎么用?Java RsWithHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RsWithHeaders类属于org.takes.rs包,在下文中一共展示了RsWithHeaders类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: act
import org.takes.rs.RsWithHeaders; //导入依赖的package包/类
@Override
public Response act(final Request req) throws IOException {
final URL url = new URL(new RqHref.Smart(req).single("u"));
return new RsWithType(
new RsWithHeaders(
new RsWithBody(
TkBadge.SVG.with("style", "round").applyTo(
new XMLDocument(
new Xembler(
new Directives()
.add("info")
.add("url")
.set(url)
.up()
.add("total")
.set(
this.base.status(url).history(
Long.MAX_VALUE
).size()
)
.up()
.add("failures")
.set(
this.base.status(url).failures(
Long.MAX_VALUE
).size()
)
.up()
).xmlQuietly()
)
)
),
"Cache-Control: no-cache"
),
"image/svg+xml"
);
}
示例2: cached
import org.takes.rs.RsWithHeaders; //导入依赖的package包/类
/**
* Response that is cached forever.
* @param rsp Response
* @return New response
*/
private static Response cached(final Response rsp) {
return new RsWithHeaders(
new RsWithoutHeader(
new RsWithoutHeader(
new RsWithoutHeader(rsp, "Age"),
"Expires"
),
"Cache-Control"
),
"Age: 31536000",
"Cache-Control: max-age=31536000",
"Expires: Sun, 19 Jul 2020 18:06:32 GMT"
);
}
示例3: response
import org.takes.rs.RsWithHeaders; //导入依赖的package包/类
/**
* Creates the response received from the target host.
*
* @param home Home host
* @param dest Destination URL
* @param rsp Response received from the target host
* @return Response
*/
private Response response(final String home, final URI dest,
final com.jcabi.http.Response rsp) {
final Collection<String> hdrs = new LinkedList<>();
hdrs.add(
String.format(
"X-Takes-TkProxy: from %s to %s by %s",
home, dest, this.label
)
);
for (final Map.Entry<String, List<String>> entry
: rsp.headers().entrySet()) {
for (final String value : entry.getValue()) {
final String val;
if (TkProxy.isHost(entry.getKey())) {
val = this.target.toString();
} else {
val = value;
}
hdrs.add(String.format("%s: %s", entry.getKey(), val));
}
}
return new RsWithStatus(
new RsWithBody(
new RsWithHeaders(hdrs),
rsp.binary()
),
rsp.status(),
rsp.reason()
);
}
示例4: TkWithHeaders
import org.takes.rs.RsWithHeaders; //导入依赖的package包/类
/**
* Ctor.
* @param take Original
* @param headers Headers
*/
public TkWithHeaders(final Take take, final Collection<String> headers) {
super(
new Take() {
@Override
public Response act(final Request req) throws IOException {
return new RsWithHeaders(take.act(req), headers);
}
}
);
}
示例5: testsHeadersAvailable
import org.takes.rs.RsWithHeaders; //导入依赖的package包/类
/**
* HmRsHeader can test headers available.
* @throws Exception If some problem inside
*/
@Test
public void testsHeadersAvailable() throws Exception {
MatcherAssert.assertThat(
new RsWithHeaders(
new RsEmpty(),
"header3: value31", "HEADER3: value32"
),
new HmRsHeader("Header3", Matchers.<String>iterableWithSize(2))
);
}
示例6: testsHeadersNotAvailable
import org.takes.rs.RsWithHeaders; //导入依赖的package包/类
/**
* HmRsHeader can test headers not available.
* @throws Exception If some problem inside
*/
@Test
public void testsHeadersNotAvailable() throws Exception {
MatcherAssert.assertThat(
new RsWithHeaders(new RsEmpty(), "header4: value4"),
new HmRsHeader("header41", Matchers.emptyIterableOf(String.class))
);
}