本文整理汇总了Java中org.takes.Request.head方法的典型用法代码示例。如果您正苦于以下问题:Java Request.head方法的具体用法?Java Request.head怎么用?Java Request.head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.takes.Request
的用法示例。
在下文中一共展示了Request.head方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: request
import org.takes.Request; //导入方法依赖的package包/类
/**
* The request to send.
* @param req Original request
* @param path Destination path
* @return Request
*/
private static Request request(final Request req, final String path) {
return new Request() {
@Override
public Iterable<String> head() throws IOException {
return new Concat<String>(
Collections.singleton(
String.format(
"GET %s HTTP/1.1",
path
)
),
new Skipped<>(req.head(), 1)
);
}
@Override
public InputStream body() throws IOException {
return req.body();
}
};
}
示例2: wrap
import org.takes.Request; //导入方法依赖的package包/类
/**
* Wrap the request.
* @param req Request
* @return New request
*/
private static Request wrap(final Request req) {
final AtomicBoolean seen = new AtomicBoolean(false);
return new Request() {
@Override
public Iterable<String> head() throws IOException {
return req.head();
}
@Override
public InputStream body() throws IOException {
if (!seen.getAndSet(true)) {
throw new IllegalStateException(
"It's not allowed to call body() more than once"
);
}
return req.body();
}
};
}
示例3: request
import org.takes.Request; //导入方法依赖的package包/类
/**
* The request to send.
* @param req Original request
* @param uri Destination URI
* @return Request
*/
private static Request request(final Request req, final URI uri) {
final StringBuilder path = new StringBuilder(0);
path.append(uri.getRawPath());
if (path.length() == 0) {
path.append('/');
}
if (uri.getQuery() != null) {
path.append('?').append(uri.getRawQuery());
}
if (uri.getFragment() != null) {
path.append('#').append(uri.getRawFragment());
}
return new Request() {
@Override
public Iterable<String> head() throws IOException {
return new Concat<>(
Collections.singleton(
String.format(
"%s %s HTTP/1.1",
new RqMethod.Base(req).method(),
path
)
),
new Skipped<>(req.head(), 1)
);
}
@Override
public InputStream body() throws IOException {
return req.body();
}
};
}
示例4: RqWithBody
import org.takes.Request; //导入方法依赖的package包/类
/**
* Ctor.
* @param req The request.
* @param bdy The body.
*/
public RqWithBody(final Request req, final CharSequence bdy) {
super(new Request() {
@Override
public Iterable<String> head() throws IOException {
return req.head();
}
@Override
public InputStream body() {
return new ByteArrayInputStream(
new Utf8String(bdy.toString()).bytes()
);
}
});
}
示例5: RqChunk
import org.takes.Request; //导入方法依赖的package包/类
/**
* Ctor.
* @param req Original request
*/
public RqChunk(final Request req) {
super(
new Request() {
@Override
public Iterable<String> head() throws IOException {
return req.head();
}
@Override
public InputStream body() throws IOException {
return RqChunk.cap(req);
}
}
);
}
示例6: consume
import org.takes.Request; //导入方法依赖的package包/类
/**
* Consume the request.
* @param req Request
* @return New request
* @throws IOException If fails
*/
private static Request consume(final Request req) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
new RqPrint(req).printBody(baos);
return new Request() {
@Override
public Iterable<String> head() throws IOException {
return req.head();
}
@Override
public InputStream body() {
return new ByteArrayInputStream(baos.toByteArray());
}
};
}
示例7: RqLengthAware
import org.takes.Request; //导入方法依赖的package包/类
/**
* Ctor.
* @param req Original request
*/
public RqLengthAware(final Request req) {
super(
new Request() {
@Override
public Iterable<String> head() throws IOException {
return req.head();
}
@Override
public InputStream body() throws IOException {
return RqLengthAware.cap(req);
}
}
);
}
示例8: RqBuffered
import org.takes.Request; //导入方法依赖的package包/类
/**
* Ctor.
* @param req Original request
*/
public RqBuffered(final Request req) {
super(
new Request() {
@Override
public Iterable<String> head() throws IOException {
return req.head();
}
@Override
public InputStream body() throws IOException {
return new BufferedInputStream(req.body());
}
}
);
}
示例9: RqWithoutHeader
import org.takes.Request; //导入方法依赖的package包/类
/**
* Ctor.
* @param req Original request
* @param name Header name
*/
public RqWithoutHeader(final Request req, final CharSequence name) {
super(
// @checkstyle AnonInnerLengthCheck (50 lines)
new Request() {
@Override
public Iterable<String> head() throws IOException {
final String prefix = String.format(
"%s:", new EnglishLowerCase(name.toString()).string()
);
return new Select<String>(
req.head(),
new Condition<String>() {
@Override
public boolean fits(final String header) {
return !new EnglishLowerCase(header).string()
.startsWith(prefix);
}
}
);
}
@Override
public InputStream body() throws IOException {
return req.body();
}
}
);
}
示例10: headers
import org.takes.Request; //导入方法依赖的package包/类
@Override
public Iterable<String> headers(final Request item) throws IOException {
return item.head();
}