CallServerInterceptor.smali 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. .class public final Lokhttp3/internal/http/CallServerInterceptor;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # interfaces
  5. .implements Lokhttp3/Interceptor;
  6. # annotations
  7. .annotation system Ldalvik/annotation/MemberClasses;
  8. value = {
  9. Lokhttp3/internal/http/CallServerInterceptor$CountingSink;
  10. }
  11. .end annotation
  12. # instance fields
  13. .field private final forWebSocket:Z
  14. # direct methods
  15. .method public constructor <init>(Z)V
  16. .locals 0
  17. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  18. iput-boolean p1, p0, Lokhttp3/internal/http/CallServerInterceptor;->forWebSocket:Z
  19. return-void
  20. .end method
  21. # virtual methods
  22. .method public intercept(Lokhttp3/Interceptor$Chain;)Lokhttp3/Response;
  23. .locals 11
  24. .annotation system Ldalvik/annotation/Throws;
  25. value = {
  26. Ljava/io/IOException;
  27. }
  28. .end annotation
  29. check-cast p1, Lokhttp3/internal/http/RealInterceptorChain;
  30. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->httpStream()Lokhttp3/internal/http/HttpCodec;
  31. move-result-object v0
  32. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->streamAllocation()Lokhttp3/internal/connection/StreamAllocation;
  33. move-result-object v1
  34. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->connection()Lokhttp3/Connection;
  35. move-result-object v2
  36. check-cast v2, Lokhttp3/internal/connection/RealConnection;
  37. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->request()Lokhttp3/Request;
  38. move-result-object v3
  39. invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
  40. move-result-wide v4
  41. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  42. move-result-object v6
  43. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  44. move-result-object v7
  45. invoke-virtual {v6, v7}, Lokhttp3/EventListener;->requestHeadersStart(Lokhttp3/Call;)V
  46. invoke-interface {v0, v3}, Lokhttp3/internal/http/HttpCodec;->writeRequestHeaders(Lokhttp3/Request;)V
  47. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  48. move-result-object v6
  49. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  50. move-result-object v7
  51. invoke-virtual {v6, v7, v3}, Lokhttp3/EventListener;->requestHeadersEnd(Lokhttp3/Call;Lokhttp3/Request;)V
  52. invoke-virtual {v3}, Lokhttp3/Request;->method()Ljava/lang/String;
  53. move-result-object v6
  54. invoke-static {v6}, Lokhttp3/internal/http/HttpMethod;->permitsRequestBody(Ljava/lang/String;)Z
  55. move-result v6
  56. const/4 v7, 0x0
  57. if-eqz v6, :cond_2
  58. invoke-virtual {v3}, Lokhttp3/Request;->body()Lokhttp3/RequestBody;
  59. move-result-object v6
  60. if-eqz v6, :cond_2
  61. const-string v6, "Expect"
  62. invoke-virtual {v3, v6}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  63. move-result-object v6
  64. const-string v8, "100-continue"
  65. invoke-virtual {v8, v6}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
  66. move-result v6
  67. if-eqz v6, :cond_0
  68. invoke-interface {v0}, Lokhttp3/internal/http/HttpCodec;->flushRequest()V
  69. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  70. move-result-object v6
  71. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  72. move-result-object v7
  73. invoke-virtual {v6, v7}, Lokhttp3/EventListener;->responseHeadersStart(Lokhttp3/Call;)V
  74. const/4 v6, 0x1
  75. invoke-interface {v0, v6}, Lokhttp3/internal/http/HttpCodec;->readResponseHeaders(Z)Lokhttp3/Response$Builder;
  76. move-result-object v7
  77. :cond_0
  78. if-nez v7, :cond_1
  79. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  80. move-result-object v2
  81. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  82. move-result-object v6
  83. invoke-virtual {v2, v6}, Lokhttp3/EventListener;->requestBodyStart(Lokhttp3/Call;)V
  84. invoke-virtual {v3}, Lokhttp3/Request;->body()Lokhttp3/RequestBody;
  85. move-result-object v2
  86. invoke-virtual {v2}, Lokhttp3/RequestBody;->contentLength()J
  87. move-result-wide v8
  88. new-instance v2, Lokhttp3/internal/http/CallServerInterceptor$CountingSink;
  89. invoke-interface {v0, v3, v8, v9}, Lokhttp3/internal/http/HttpCodec;->createRequestBody(Lokhttp3/Request;J)Lokio/Sink;
  90. move-result-object v6
  91. invoke-direct {v2, v6}, Lokhttp3/internal/http/CallServerInterceptor$CountingSink;-><init>(Lokio/Sink;)V
  92. invoke-static {v2}, Lokio/Okio;->buffer(Lokio/Sink;)Lokio/BufferedSink;
  93. move-result-object v6
  94. invoke-virtual {v3}, Lokhttp3/Request;->body()Lokhttp3/RequestBody;
  95. move-result-object v8
  96. invoke-virtual {v8, v6}, Lokhttp3/RequestBody;->writeTo(Lokio/BufferedSink;)V
  97. invoke-interface {v6}, Lokio/Sink;->close()V
  98. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  99. move-result-object v6
  100. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  101. move-result-object v8
  102. iget-wide v9, v2, Lokhttp3/internal/http/CallServerInterceptor$CountingSink;->successfulCount:J
  103. invoke-virtual {v6, v8, v9, v10}, Lokhttp3/EventListener;->requestBodyEnd(Lokhttp3/Call;J)V
  104. goto :goto_0
  105. :cond_1
  106. invoke-virtual {v2}, Lokhttp3/internal/connection/RealConnection;->isMultiplexed()Z
  107. move-result v2
  108. if-nez v2, :cond_2
  109. invoke-virtual {v1}, Lokhttp3/internal/connection/StreamAllocation;->noNewStreams()V
  110. :cond_2
  111. :goto_0
  112. invoke-interface {v0}, Lokhttp3/internal/http/HttpCodec;->finishRequest()V
  113. if-nez v7, :cond_3
  114. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  115. move-result-object v2
  116. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  117. move-result-object v6
  118. invoke-virtual {v2, v6}, Lokhttp3/EventListener;->responseHeadersStart(Lokhttp3/Call;)V
  119. const/4 v2, 0x0
  120. invoke-interface {v0, v2}, Lokhttp3/internal/http/HttpCodec;->readResponseHeaders(Z)Lokhttp3/Response$Builder;
  121. move-result-object v7
  122. :cond_3
  123. invoke-virtual {v7, v3}, Lokhttp3/Response$Builder;->request(Lokhttp3/Request;)Lokhttp3/Response$Builder;
  124. move-result-object v2
  125. invoke-virtual {v1}, Lokhttp3/internal/connection/StreamAllocation;->connection()Lokhttp3/internal/connection/RealConnection;
  126. move-result-object v3
  127. invoke-virtual {v3}, Lokhttp3/internal/connection/RealConnection;->handshake()Lokhttp3/Handshake;
  128. move-result-object v3
  129. invoke-virtual {v2, v3}, Lokhttp3/Response$Builder;->handshake(Lokhttp3/Handshake;)Lokhttp3/Response$Builder;
  130. move-result-object v2
  131. invoke-virtual {v2, v4, v5}, Lokhttp3/Response$Builder;->sentRequestAtMillis(J)Lokhttp3/Response$Builder;
  132. move-result-object v2
  133. invoke-static {}, Ljava/lang/System;->currentTimeMillis()J
  134. move-result-wide v3
  135. invoke-virtual {v2, v3, v4}, Lokhttp3/Response$Builder;->receivedResponseAtMillis(J)Lokhttp3/Response$Builder;
  136. move-result-object v2
  137. invoke-virtual {v2}, Lokhttp3/Response$Builder;->build()Lokhttp3/Response;
  138. move-result-object v2
  139. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->eventListener()Lokhttp3/EventListener;
  140. move-result-object v3
  141. invoke-virtual {p1}, Lokhttp3/internal/http/RealInterceptorChain;->call()Lokhttp3/Call;
  142. move-result-object p1
  143. invoke-virtual {v3, p1, v2}, Lokhttp3/EventListener;->responseHeadersEnd(Lokhttp3/Call;Lokhttp3/Response;)V
  144. invoke-virtual {v2}, Lokhttp3/Response;->code()I
  145. move-result p1
  146. iget-boolean v3, p0, Lokhttp3/internal/http/CallServerInterceptor;->forWebSocket:Z
  147. if-eqz v3, :cond_4
  148. const/16 v3, 0x65
  149. if-ne p1, v3, :cond_4
  150. invoke-virtual {v2}, Lokhttp3/Response;->newBuilder()Lokhttp3/Response$Builder;
  151. move-result-object v0
  152. sget-object v2, Lokhttp3/internal/Util;->EMPTY_RESPONSE:Lokhttp3/ResponseBody;
  153. invoke-virtual {v0, v2}, Lokhttp3/Response$Builder;->body(Lokhttp3/ResponseBody;)Lokhttp3/Response$Builder;
  154. move-result-object v0
  155. goto :goto_1
  156. :cond_4
  157. invoke-virtual {v2}, Lokhttp3/Response;->newBuilder()Lokhttp3/Response$Builder;
  158. move-result-object v3
  159. invoke-interface {v0, v2}, Lokhttp3/internal/http/HttpCodec;->openResponseBody(Lokhttp3/Response;)Lokhttp3/ResponseBody;
  160. move-result-object v0
  161. invoke-virtual {v3, v0}, Lokhttp3/Response$Builder;->body(Lokhttp3/ResponseBody;)Lokhttp3/Response$Builder;
  162. move-result-object v0
  163. :goto_1
  164. invoke-virtual {v0}, Lokhttp3/Response$Builder;->build()Lokhttp3/Response;
  165. move-result-object v0
  166. invoke-virtual {v0}, Lokhttp3/Response;->request()Lokhttp3/Request;
  167. move-result-object v2
  168. const-string v3, "Connection"
  169. invoke-virtual {v2, v3}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  170. move-result-object v2
  171. const-string v4, "close"
  172. invoke-virtual {v4, v2}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
  173. move-result v2
  174. if-nez v2, :cond_5
  175. invoke-virtual {v0, v3}, Lokhttp3/Response;->header(Ljava/lang/String;)Ljava/lang/String;
  176. move-result-object v2
  177. invoke-virtual {v4, v2}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
  178. move-result v2
  179. if-eqz v2, :cond_6
  180. :cond_5
  181. invoke-virtual {v1}, Lokhttp3/internal/connection/StreamAllocation;->noNewStreams()V
  182. :cond_6
  183. const/16 v1, 0xcc
  184. if-eq p1, v1, :cond_7
  185. const/16 v1, 0xcd
  186. if-ne p1, v1, :cond_8
  187. :cond_7
  188. invoke-virtual {v0}, Lokhttp3/Response;->body()Lokhttp3/ResponseBody;
  189. move-result-object v1
  190. invoke-virtual {v1}, Lokhttp3/ResponseBody;->contentLength()J
  191. move-result-wide v1
  192. const-wide/16 v3, 0x0
  193. cmp-long v5, v1, v3
  194. if-gtz v5, :cond_9
  195. :cond_8
  196. return-object v0
  197. :cond_9
  198. new-instance v1, Ljava/net/ProtocolException;
  199. new-instance v2, Ljava/lang/StringBuilder;
  200. invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
  201. const-string v3, "HTTP "
  202. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  203. invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
  204. const-string p1, " had non-zero Content-Length: "
  205. invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  206. invoke-virtual {v0}, Lokhttp3/Response;->body()Lokhttp3/ResponseBody;
  207. move-result-object p1
  208. invoke-virtual {p1}, Lokhttp3/ResponseBody;->contentLength()J
  209. move-result-wide v3
  210. invoke-virtual {v2, v3, v4}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  211. invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  212. move-result-object p1
  213. invoke-direct {v1, p1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  214. throw v1
  215. .end method