NoHttp_arch
2017-04-20 05:21:19 0 举报
NoHttp_arch是一个开源的HTTP代理服务器,它专为Android操作系统设计。这个代理服务器的主要目标是提供一个安全、高效且易于使用的网络连接解决方案。NoHttp_arch支持多种协议,包括HTTP、HTTPS、FTP等,并且可以配置为透明模式或全局模式。此外,它还具有负载均衡和缓存功能,可以提高网络性能。NoHttp_arch的设计非常灵活,可以根据用户的需求进行定制。它的源代码是开放的,这意味着任何人都可以查看和修改它,以满足自己的特定需求。总的来说,NoHttp_arch是一个强大而实用的工具,可以帮助用户更好地管理和优化他们的网络连接。
作者其他创作
大纲/内容
URLConnectionNetworkExecutor
HttpConnection.createConnectionAndWriteData()
RequestDispatcher
- BlockingQueueRequestmRequestQueue- BlockingQueueRequestmUnFinishQueue- Delivery mDelivery- boolean mQuit
+ void quit()+ void run()
从网络中获取
Protocol result=new Protocol();Connection connection=mHttpConnection.getConnection(request);result.headers=connection.responseHeaders();result.exception=connection.exception();result.body=IOUtils.toByteArray(connection.serverStream());
RequestQueue
- AtomicInteger mInteger- BlockingQueueRequestmUnFinishQueue- BlockingQueueRequestmRequestQueue- RequestDispatcher[] mDispatchers- Delivery mDelivery
protocol=getHttpProtocol(request);
Queueable
+ setQueue(BlockingQueue+ boolean inQueue()
RequestDispatcher.run()
Finishable
+ void finish()+ boolean isFinished()
RestProtocol
- CacheStoremCacheStore- HttpConnection mHttpConnection
HttpConnection.getConnection()
所以,如果要抽象的话,就要从java.net.HttpURLConnection的属性设置,以及执行结果出发去进行抽象,至少Request和Response是可以抽象出来
所以,如果要写一个非常简单的,那就是抽象程序非常小的HttpClient;否则就是抽象程度高的
OkHttpNetworkExecutor
+ Network execute(IBasicRequest request)
Network
protocol=new Protocol();protocol.headers=localCache.getResponseHeaders();protocol.body=localCache.getData();protocol.fromCache=true;
Headers
enum SyncRequestExecutor
+ INSTANCE- RestProtocol mRestProtocol
+ SyncRequestExecutor()+ Respose execute(IProtocolRequest)
IBasicRequest
HttpConnection
- NetworkExecutor mExecutor
RequestTask
- Requestrequest- Delivery mDelivery
HttpConnection.createNetwork()
Startable
+ void start()+ boolean isStarted()
Response response=SyncRequestExecutor.INSTANCE.execute(request);
Request
RestProtocol.request()
URLConnectionNetwork
+ HttpURLConnection
从缓存中获取
从缓存或网络获取数据
Cancelable
+ void cancel()+ boolean isCanceled()
RestProtocol.Protocol
- Headers headers- boolean fromCache- byte[]body- Exception exception
Connection
- Network network- Headers mResponseHeaders- InputStream mServerStream- Exception mException
另外,把OnResponseListener也放到Request中不是一种好的做法
mExecutor.execute(request)
URLConnectionNetworkExecutor.execute()
NetworkExecutor
RestResponse
- IProtocolRequest request- boolean isFromCache- Headers headers- T result- long mNetworkMillis- Exception mException
Response
+ IProtocolRequest request()+ int responseCode()+ boolean isSucceed()+ boolean isFromCache()+ Headers getHeaders()+ T get()+ Exception getException()+ Object getTag()+ long getNetworkMillis()
其实头部没必要搞这么复杂的,因为有很多共同的地方,用一个方法就可以搞定
Runnable
IProtocolRequest
enum AsyncRequestExecutor
+ INSTANCE- Delivery mDelivery- ExecutorService mExecutorService
0 条评论
下一页