本文整理汇总了Java中com.koushikdutta.async.http.server.AsyncHttpServerResponse.code方法的典型用法代码示例。如果您正苦于以下问题:Java AsyncHttpServerResponse.code方法的具体用法?Java AsyncHttpServerResponse.code怎么用?Java AsyncHttpServerResponse.code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.koushikdutta.async.http.server.AsyncHttpServerResponse
的用法示例。
在下文中一共展示了AsyncHttpServerResponse.code方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebSocketImpl
import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入方法依赖的package包/类
public WebSocketImpl(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
this(request.getSocket());
String key = request.getHeaders().get("Sec-WebSocket-Key");
String concat = key + MAGIC;
String sha1 = SHA1(concat);
String origin = request.getHeaders().get("Origin");
response.code(101);
response.getHeaders().set("Upgrade", "WebSocket");
response.getHeaders().set("Connection", "Upgrade");
response.getHeaders().set("Sec-WebSocket-Accept", sha1);
String protocol = request.getHeaders().get("Sec-WebSocket-Protocol");
// match the protocol (sanity checking and enforcement is done in the caller)
if (!TextUtils.isEmpty(protocol))
response.getHeaders().set("Sec-WebSocket-Protocol", protocol);
// if (origin != null)
// response.getHeaders().getHeaders().set("Access-Control-Allow-Origin", "http://" + origin);
response.writeHead();
setupParser(false, false);
}
示例2: onRequest
import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入方法依赖的package包/类
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
if (true) {
Log.i(Main.TAG, "screenshot authentication success");
try {
Bitmap bitmap = EncoderFeeder.screenshot(this.val$wm);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bout);
bout.flush();
response.send("image/jpeg", bout.toByteArray());
return;
} catch (Exception e) {
response.code(500);
response.send(e.toString());
return;
}
}
Log.i(Main.TAG, "screenshot authentication failed");
response.code(401);
response.send("Not Authorized.");
}
示例3: onRequest
import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入方法依赖的package包/类
public void onRequest(AsyncHttpServerRequest asyncHttpServerRequest, AsyncHttpServerResponse httpServerResponse) {
if (sCurrentVideo != null && sCurrentVideo.exists()) {
mFileType.setHeaders(httpServerResponse);
httpServerResponse.sendFile(sCurrentVideo);
} else {
httpServerResponse.send("Not found");
httpServerResponse.code(404);
}
Timber.i(httpServerResponse.toString());
}
示例4: shouldPass
import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入方法依赖的package包/类
private boolean shouldPass(final AsyncHttpServerRequest req, final AsyncHttpServerResponse res) {
if (isStopped) {
res.code(404);
res.end();
return false;
}
if (!isAuthenticated(req)) {
res.getHeaders().add("WWW-Authenticate", "Basic realm=\"DeviceControl\"");
res.code(401);
res.end();
return false;
}
return true;
}