本文整理汇总了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;
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例6: getRawHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public Headers getRawHeaders() {
return mHeaders;
}
示例7: getHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
@Override
public Headers getHeaders() {
return mRawHeaders;
}
示例8: onUnknownBody
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
protected AsyncHttpRequestBody onUnknownBody(Headers headers) {
return new UnknownRequestBody(headers.get("Content-Type"));
}
示例9: onUnknownBody
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
protected AsyncHttpRequestBody onUnknownBody(Headers headers) {
return null;
}
示例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++;
}
示例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++;
}
示例12: getHeaders
import com.koushikdutta.async.http.Headers; //导入依赖的package包/类
public Headers getHeaders();