use of okhttp3.internal.http2.Header in project okhttp by square.
the class WebSocketHttpTest method wrongMagicHeader.
@Test
public void wrongMagicHeader() throws IOException {
webServer.enqueue(new MockResponse().setResponseCode(101).setHeader("Connection", "Upgrade").setHeader("Upgrade", "websocket").setHeader("Sec-WebSocket-Accept", "magic"));
newWebSocket();
clientListener.assertFailure(101, null, ProtocolException.class, "Expected 'Sec-WebSocket-Accept' header value 'ujmZX4KXZqjwy6vi1aQFH5p4Ygk=' but was 'magic'");
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class WebSocketHttpTest method wrongUpgradeHeader.
@Test
public void wrongUpgradeHeader() throws IOException {
webServer.enqueue(new MockResponse().setResponseCode(101).setHeader("Connection", "Upgrade").setHeader("Upgrade", "Pepsi").setHeader("Sec-WebSocket-Accept", "ujmZX4KXZqjwy6vi1aQFH5p4Ygk="));
newWebSocket();
clientListener.assertFailure(101, null, ProtocolException.class, "Expected 'Upgrade' header value 'websocket' but was 'Pepsi'");
}
use of okhttp3.internal.http2.Header in project cas by apereo.
the class SamlProfileSamlSoap11FaultResponseBuilder method build.
@Override
public Envelope build(final AuthnRequest authnRequest, final HttpServletRequest request, final HttpServletResponse response, final org.jasig.cas.client.validation.Assertion casAssertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) throws SamlException {
final Header header = newSoapObject(Header.class);
final Body body = newSoapObject(Body.class);
final Fault fault = newSoapObject(Fault.class);
final FaultCode faultCode = newSoapObject(FaultCode.class);
faultCode.setValue(FaultCode.SERVER);
fault.setCode(faultCode);
final FaultActor faultActor = newSoapObject(FaultActor.class);
faultActor.setValue(SamlIdPUtils.getIssuerFromSamlRequest(authnRequest));
fault.setActor(faultActor);
final FaultString faultString = newSoapObject(FaultString.class);
faultString.setValue(request.getAttribute(SamlIdPConstants.REQUEST_ATTRIBUTE_ERROR).toString());
fault.setMessage(faultString);
body.getUnknownXMLObjects().add(fault);
final Envelope envelope = newSoapObject(Envelope.class);
envelope.setHeader(header);
envelope.setBody(body);
encodeFinalResponse(request, response, service, adaptor, envelope);
return envelope;
}
use of okhttp3.internal.http2.Header in project OkHttp3 by MrZhousf.
the class DownUpLoadHelper method downloadFile.
/**
* 文件下载
*/
void downloadFile(final OkHttpHelper helper) {
try {
final HttpInfo info = httpInfo;
final DownloadFileInfo fileInfo = helper.getDownloadFileInfo();
String url = fileInfo.getUrl();
if (TextUtils.isEmpty(url)) {
showLog("下载文件失败:文件下载地址不能为空!");
return;
}
info.setUrl(url);
ProgressCallback progressCallback = fileInfo.getProgressCallback();
//获取文件断点
long completedSize = fetchCompletedSize(fileInfo);
fileInfo.setCompletedSize(completedSize);
//添加下载任务
if (null == downloadTaskMap)
downloadTaskMap = new ConcurrentHashMap<>();
if (downloadTaskMap.containsKey(fileInfo.getSaveFileNameEncrypt())) {
showLog(fileInfo.getSaveFileName() + " 已在下载任务中");
return;
}
downloadTaskMap.put(fileInfo.getSaveFileNameEncrypt(), fileInfo.getSaveFileNameEncrypt());
Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder().body(new ProgressResponseBody(originalResponse.body(), fileInfo, timeStamp, requestTag)).build();
}
};
//采用新的OkHttpClient处理多线程干扰回调进度问题
OkHttpClient httpClient = helper.getClientBuilder().addInterceptor(interceptor).build();
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.url(url).header("RANGE", "bytes=" + completedSize + "-");
helper.getHttpHelper().addHeadsToRequest(info, requestBuilder);
Request request = requestBuilder.build();
helper.setRequest(request);
helper.setHttpClient(httpClient);
helper.getHttpHelper().responseCallback(helper.doRequestSync(), progressCallback, OkMainHandler.RESPONSE_DOWNLOAD_CALLBACK, requestTag);
//删除下载任务
if (null != downloadTaskMap) {
downloadTaskMap.remove(fileInfo.getSaveFileNameEncrypt());
}
} catch (Exception e) {
showLog("下载文件失败:" + e.getMessage());
}
}
use of okhttp3.internal.http2.Header in project yyl_example by Relucent.
the class OkhttpTest2 method main.
public static void main(String[] args) throws IOException {
OkHttpClient client;
(client = //
new OkHttpClient.Builder().build()).newCall(//
new Request.Builder().url(//
"https://www.baidu.com/").header("Connection", //close | keep-alive
"close").get().build()).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
System.out.println(response.body().string());
}
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
});
//应用关闭时候需要关闭线程池
client.dispatcher().executorService().shutdown();
}
Aggregations