本文整理汇总了Java中com.koushikdutta.async.http.Headers类的典型用法代码示例。如果您正苦于以下问题:Java Headers类的具体用法?Java Headers怎么用?Java Headers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Headers类属于com.koushikdutta.async.http包,在下文中一共展示了Headers类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convert
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
private Response convert(Request request, AsyncHttpResponse response, String s) {
Response res = new Response();
res.setCode(response.code());
res.setMessage(response.message());
res.setProtocol(response.protocol());
res.setBody(s);
res.setSourceBody(s.getBytes());
Type type = request.getBusinessType();
if (type != null) {
res.setBussinessResponse(JsonUtil.fromJson(s, type));
}
Headers headers = response.headers();
Multimap multimap = headers.getMultiMap();
Set<String> keySet = multimap.keySet();
for (String key : keySet) {
res.addHeader(key, multimap.get(key));
}
res.setRequest(request);
return res;
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:21,代码来源:NetworkDelegate.java
示例2: onBoundaryStart
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
@Override
protected void onBoundaryStart() {
final Headers headers = new Headers();
liner = new LineEmitter();
liner.setLineCallback(new StringCallback() {
@Override
public void onStringAvailable(String s) {
if (!"\r".equals(s)){
headers.addLine(s);
}
else {
handleLast();
liner = null;
setDataCallback(null);
Part part = new Part(headers);
if (mCallback != null)
mCallback.onPart(part);
if (getDataCallback() == null) {
if (part.isFile()) {
setDataCallback(new NullDataCallback());
return;
}
lastName = part.getName();
last = new ByteBufferList();
setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
bb.get(last);
}
});
}
}
}
});
setDataCallback(liner);
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:39,代码来源:MultipartFormDataBody.java
示例3: Part
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public Part(String name, long length, List<NameValuePair> contentDisposition) {
this.length = length;
mHeaders = new Headers();
StringBuilder builder = new StringBuilder(String.format(Locale.ENGLISH, "form-data; name=\"%s\"", name));
if (contentDisposition != null) {
for (NameValuePair pair: contentDisposition) {
builder.append(String.format(Locale.ENGLISH, "; %s=\"%s\"", pair.getName(), pair.getValue()));
}
}
mHeaders.set(CONTENT_DISPOSITION, builder.toString());
mContentDisposition = Multimap.parseSemicolonDelimited(mHeaders.get(CONTENT_DISPOSITION));
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:13,代码来源:Part.java
示例4: Part
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public Part(String name, long length, List<NameValuePair> contentDisposition) {
this.length = length;
mHeaders = new Headers();
StringBuilder builder = new StringBuilder(String.format("form-data; name=\"%s\"", name));
if (contentDisposition != null) {
for (NameValuePair pair: contentDisposition) {
builder.append(String.format("; %s=\"%s\"", pair.getName(), pair.getValue()));
}
}
mHeaders.set(CONTENT_DISPOSITION, builder.toString());
mContentDisposition = Multimap.parseSemicolonDelimited(mHeaders.get(CONTENT_DISPOSITION));
}
开发者ID:BeckNiu,项目名称:MyCar,代码行数:13,代码来源:Part.java
示例5: setHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public void setHeaders(Headers paramHeaders) {
paramHeaders.set("contentFeatures.dlna.org", this.dlnaContentFeatures);
paramHeaders.set("TransferMode.DLNA.ORG", this.dlnaTransferMode);
paramHeaders.set("DAAP-Server", "iTunes/11.0.5 (OS X)");
paramHeaders.set("Date", HttpDate.format(new Date()));
paramHeaders.set("Last-Modified", "2015-01-01T10:00:00Z");
paramHeaders.set("Content-Type", this.mimeType);
paramHeaders.set("CaptionInfo.sec", getSubsURL(SRT));
}
开发者ID:PTCE,项目名称:popcorn-android,代码行数:10,代码来源:BeamServer.java
示例6: getRawHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public Headers getRawHeaders() {
return mHeaders;
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:4,代码来源:Part.java
示例7: getHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
@Override
public Headers getHeaders() {
return mRawHeaders;
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:5,代码来源:AsyncHttpServerResponseImpl.java
示例8: onUnknownBody
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
protected AsyncHttpRequestBody onUnknownBody(Headers headers) {
return new UnknownRequestBody(headers.get("Content-Type"));
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:4,代码来源:AsyncHttpServer.java
示例9: onUnknownBody
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
protected AsyncHttpRequestBody onUnknownBody(Headers headers) {
return null;
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:4,代码来源:AsyncHttpServerRequestImpl.java
示例10: onBodyDecoder
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
@Override
public void onBodyDecoder(OnBodyDataOnRequestSentData data) {
CachedSocket cached = com.koushikdutta.async.Util.getWrappedSocket(data.socket, CachedSocket.class);
if (cached != null) {
data.response.headers().set(SERVED_FROM, CACHE);
return;
}
CacheData cacheData = data.state.get("cache-data");
RawHeaders rh = RawHeaders.fromMultimap(data.response.headers().getMultiMap());
rh.removeAll("Content-Length");
rh.setStatusLine(String.format(Locale.ENGLISH, "%s %s %s", data.response.protocol(), data.response.code(), data.response.message()));
ResponseHeaders networkResponse = new ResponseHeaders(data.request.getUri(), rh);
data.state.put("response-headers", networkResponse);
if (cacheData != null) {
if (cacheData.cachedResponseHeaders.validate(networkResponse)) {
data.request.logi("Serving response from conditional cache");
ResponseHeaders combined = cacheData.cachedResponseHeaders.combine(networkResponse);
data.response.headers(new Headers(combined.getHeaders().toMultimap()));
data.response.code(combined.getHeaders().getResponseCode());
data.response.message(combined.getHeaders().getResponseMessage());
data.response.headers().set(SERVED_FROM, CONDITIONAL_CACHE);
conditionalCacheHitCount++;
CachedBodyEmitter bodySpewer = new CachedBodyEmitter(cacheData.candidate, cacheData.contentLength);
bodySpewer.setDataEmitter(data.bodyEmitter);
data.bodyEmitter = bodySpewer;
bodySpewer.sendCachedData();
return;
}
// did not validate, so fall through and cache the response
data.state.remove("cache-data");
StreamUtility.closeQuietly(cacheData.snapshot);
}
if (!caching)
return;
RequestHeaders requestHeaders = data.state.get("request-headers");
if (requestHeaders == null || !networkResponse.isCacheable(requestHeaders) || !data.request.getMethod().equals(AsyncHttpGet.METHOD)) {
/*
* Don't cache non-GET responses. We're technically allowed to cache
* HEAD requests and some POST requests, but the complexity of doing
* so is high and the benefit is low.
*/
networkCount++;
data.request.logd("Response is not cacheable");
return;
}
String key = FileCache.toKeyString(data.request.getUri());
RawHeaders varyHeaders = requestHeaders.getHeaders().getAll(networkResponse.getVaryFields());
Entry entry = new Entry(data.request.getUri(), varyHeaders, data.request, networkResponse.getHeaders());
BodyCacher cacher = new BodyCacher();
EntryEditor editor = new EntryEditor(key);
try {
entry.writeTo(editor);
// create the file
editor.newOutputStream(ENTRY_BODY);
}
catch (Exception e) {
// Log.e(LOGTAG, "error", e);
editor.abort();
networkCount++;
return;
}
cacher.editor = editor;
cacher.setDataEmitter(data.bodyEmitter);
data.bodyEmitter = cacher;
data.state.put("body-cacher", cacher);
data.request.logd("Caching response");
cacheStoreCount++;
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:78,代码来源:ResponseCacheMiddleware.java
示例11: onBodyDecoder
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
@Override
public void onBodyDecoder(OnBodyDataOnRequestSentData data) {
CachedSocket cached = com.koushikdutta.async.Util.getWrappedSocket(data.socket, CachedSocket.class);
if (cached != null) {
data.response.headers().set(SERVED_FROM, CACHE);
return;
}
CacheData cacheData = data.state.get("cache-data");
RawHeaders rh = RawHeaders.fromMultimap(data.response.headers().getMultiMap());
rh.removeAll("Content-Length");
rh.setStatusLine(String.format("%s %s %s", data.response.protocol(), data.response.code(), data.response.message()));
ResponseHeaders networkResponse = new ResponseHeaders(data.request.getUri(), rh);
data.state.put("response-headers", networkResponse);
if (cacheData != null) {
if (cacheData.cachedResponseHeaders.validate(networkResponse)) {
data.request.logi("Serving response from conditional cache");
ResponseHeaders combined = cacheData.cachedResponseHeaders.combine(networkResponse);
data.response.headers(new Headers(combined.getHeaders().toMultimap()));
data.response.code(combined.getHeaders().getResponseCode());
data.response.message(combined.getHeaders().getResponseMessage());
data.response.headers().set(SERVED_FROM, CONDITIONAL_CACHE);
conditionalCacheHitCount++;
CachedBodyEmitter bodySpewer = new CachedBodyEmitter(cacheData.candidate, cacheData.contentLength);
bodySpewer.setDataEmitter(data.bodyEmitter);
data.bodyEmitter = bodySpewer;
bodySpewer.sendCachedData();
return;
}
// did not validate, so fall through and cache the response
data.state.remove("cache-data");
StreamUtility.closeQuietly(cacheData.snapshot);
}
if (!caching)
return;
RequestHeaders requestHeaders = data.state.get("request-headers");
if (requestHeaders == null || !networkResponse.isCacheable(requestHeaders) || !data.request.getMethod().equals(AsyncHttpGet.METHOD)) {
/*
* Don't cache non-GET responses. We're technically allowed to cache
* HEAD requests and some POST requests, but the complexity of doing
* so is high and the benefit is low.
*/
networkCount++;
data.request.logd("Response is not cacheable");
return;
}
String key = FileCache.toKeyString(data.request.getUri());
RawHeaders varyHeaders = requestHeaders.getHeaders().getAll(networkResponse.getVaryFields());
Entry entry = new Entry(data.request.getUri(), varyHeaders, data.request, networkResponse.getHeaders());
BodyCacher cacher = new BodyCacher();
EntryEditor editor = new EntryEditor(key);
try {
entry.writeTo(editor);
// create the file
editor.newOutputStream(ENTRY_BODY);
}
catch (Exception e) {
// Log.e(LOGTAG, "error", e);
editor.abort();
networkCount++;
return;
}
cacher.editor = editor;
cacher.setDataEmitter(data.bodyEmitter);
data.bodyEmitter = cacher;
data.state.put("body-cacher", cacher);
data.request.logd("Caching response");
cacheStoreCount++;
}
开发者ID:BeckNiu,项目名称:MyCar,代码行数:78,代码来源:ResponseCacheMiddleware.java
示例12: getHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public Headers getHeaders();
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:AsyncHttpServerResponse.java
注:本文中的com.koushikdutta.async.http.Headers类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论