BridgeInterceptor.smali 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. .class public final Lokhttp3/internal/http/BridgeInterceptor;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # interfaces
  5. .implements Lokhttp3/Interceptor;
  6. # instance fields
  7. .field private final cookieJar:Lokhttp3/CookieJar;
  8. # direct methods
  9. .method public constructor <init>(Lokhttp3/CookieJar;)V
  10. .locals 0
  11. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  12. iput-object p1, p0, Lokhttp3/internal/http/BridgeInterceptor;->cookieJar:Lokhttp3/CookieJar;
  13. return-void
  14. .end method
  15. .method private cookieHeader(Ljava/util/List;)Ljava/lang/String;
  16. .locals 5
  17. .annotation system Ldalvik/annotation/Signature;
  18. value = {
  19. "(",
  20. "Ljava/util/List<",
  21. "Lokhttp3/Cookie;",
  22. ">;)",
  23. "Ljava/lang/String;"
  24. }
  25. .end annotation
  26. new-instance v0, Ljava/lang/StringBuilder;
  27. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  28. invoke-interface {p1}, Ljava/util/List;->size()I
  29. move-result v1
  30. const/4 v2, 0x0
  31. :goto_0
  32. if-ge v2, v1, :cond_1
  33. if-lez v2, :cond_0
  34. const-string v3, "; "
  35. invoke-virtual {v0, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  36. :cond_0
  37. invoke-interface {p1, v2}, Ljava/util/List;->get(I)Ljava/lang/Object;
  38. move-result-object v3
  39. check-cast v3, Lokhttp3/Cookie;
  40. invoke-virtual {v3}, Lokhttp3/Cookie;->name()Ljava/lang/String;
  41. move-result-object v4
  42. invoke-virtual {v0, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  43. const/16 v4, 0x3d
  44. invoke-virtual {v0, v4}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;
  45. invoke-virtual {v3}, Lokhttp3/Cookie;->value()Ljava/lang/String;
  46. move-result-object v3
  47. invoke-virtual {v0, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  48. add-int/lit8 v2, v2, 0x1
  49. goto :goto_0
  50. :cond_1
  51. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  52. move-result-object p1
  53. return-object p1
  54. .end method
  55. # virtual methods
  56. .method public intercept(Lokhttp3/Interceptor$Chain;)Lokhttp3/Response;
  57. .locals 10
  58. .annotation system Ldalvik/annotation/Throws;
  59. value = {
  60. Ljava/io/IOException;
  61. }
  62. .end annotation
  63. invoke-interface {p1}, Lokhttp3/Interceptor$Chain;->request()Lokhttp3/Request;
  64. move-result-object v0
  65. invoke-virtual {v0}, Lokhttp3/Request;->newBuilder()Lokhttp3/Request$Builder;
  66. move-result-object v1
  67. invoke-virtual {v0}, Lokhttp3/Request;->body()Lokhttp3/RequestBody;
  68. move-result-object v2
  69. const-string v3, "Content-Type"
  70. const-wide/16 v4, -0x1
  71. const-string v6, "Content-Length"
  72. if-eqz v2, :cond_2
  73. invoke-virtual {v2}, Lokhttp3/RequestBody;->contentType()Lokhttp3/MediaType;
  74. move-result-object v7
  75. if-eqz v7, :cond_0
  76. invoke-virtual {v7}, Lokhttp3/MediaType;->toString()Ljava/lang/String;
  77. move-result-object v7
  78. invoke-virtual {v1, v3, v7}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  79. :cond_0
  80. invoke-virtual {v2}, Lokhttp3/RequestBody;->contentLength()J
  81. move-result-wide v7
  82. const-string v2, "Transfer-Encoding"
  83. cmp-long v9, v7, v4
  84. if-eqz v9, :cond_1
  85. invoke-static {v7, v8}, Ljava/lang/Long;->toString(J)Ljava/lang/String;
  86. move-result-object v7
  87. invoke-virtual {v1, v6, v7}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  88. invoke-virtual {v1, v2}, Lokhttp3/Request$Builder;->removeHeader(Ljava/lang/String;)Lokhttp3/Request$Builder;
  89. goto :goto_0
  90. :cond_1
  91. const-string v7, "chunked"
  92. invoke-virtual {v1, v2, v7}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  93. invoke-virtual {v1, v6}, Lokhttp3/Request$Builder;->removeHeader(Ljava/lang/String;)Lokhttp3/Request$Builder;
  94. :cond_2
  95. :goto_0
  96. const-string v2, "Host"
  97. invoke-virtual {v0, v2}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  98. move-result-object v7
  99. const/4 v8, 0x0
  100. if-nez v7, :cond_3
  101. invoke-virtual {v0}, Lokhttp3/Request;->url()Lokhttp3/HttpUrl;
  102. move-result-object v7
  103. invoke-static {v7, v8}, Lokhttp3/internal/Util;->hostHeader(Lokhttp3/HttpUrl;Z)Ljava/lang/String;
  104. move-result-object v7
  105. invoke-virtual {v1, v2, v7}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  106. :cond_3
  107. const-string v2, "Connection"
  108. invoke-virtual {v0, v2}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  109. move-result-object v7
  110. if-nez v7, :cond_4
  111. const-string v7, "Keep-Alive"
  112. invoke-virtual {v1, v2, v7}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  113. :cond_4
  114. const-string v2, "Accept-Encoding"
  115. invoke-virtual {v0, v2}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  116. move-result-object v7
  117. const-string v9, "gzip"
  118. if-nez v7, :cond_5
  119. const-string v7, "Range"
  120. invoke-virtual {v0, v7}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  121. move-result-object v7
  122. if-nez v7, :cond_5
  123. const/4 v8, 0x1
  124. invoke-virtual {v1, v2, v9}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  125. :cond_5
  126. iget-object v2, p0, Lokhttp3/internal/http/BridgeInterceptor;->cookieJar:Lokhttp3/CookieJar;
  127. invoke-virtual {v0}, Lokhttp3/Request;->url()Lokhttp3/HttpUrl;
  128. move-result-object v7
  129. invoke-interface {v2, v7}, Lokhttp3/CookieJar;->loadForRequest(Lokhttp3/HttpUrl;)Ljava/util/List;
  130. move-result-object v2
  131. invoke-interface {v2}, Ljava/util/List;->isEmpty()Z
  132. move-result v7
  133. if-nez v7, :cond_6
  134. invoke-direct {p0, v2}, Lokhttp3/internal/http/BridgeInterceptor;->cookieHeader(Ljava/util/List;)Ljava/lang/String;
  135. move-result-object v2
  136. const-string v7, "Cookie"
  137. invoke-virtual {v1, v7, v2}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  138. :cond_6
  139. const-string v2, "User-Agent"
  140. invoke-virtual {v0, v2}, Lokhttp3/Request;->header(Ljava/lang/String;)Ljava/lang/String;
  141. move-result-object v7
  142. if-nez v7, :cond_7
  143. invoke-static {}, Lokhttp3/internal/Version;->userAgent()Ljava/lang/String;
  144. move-result-object v7
  145. invoke-virtual {v1, v2, v7}, Lokhttp3/Request$Builder;->header(Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
  146. :cond_7
  147. invoke-virtual {v1}, Lokhttp3/Request$Builder;->build()Lokhttp3/Request;
  148. move-result-object v1
  149. invoke-interface {p1, v1}, Lokhttp3/Interceptor$Chain;->proceed(Lokhttp3/Request;)Lokhttp3/Response;
  150. move-result-object p1
  151. iget-object v1, p0, Lokhttp3/internal/http/BridgeInterceptor;->cookieJar:Lokhttp3/CookieJar;
  152. invoke-virtual {v0}, Lokhttp3/Request;->url()Lokhttp3/HttpUrl;
  153. move-result-object v2
  154. invoke-virtual {p1}, Lokhttp3/Response;->headers()Lokhttp3/Headers;
  155. move-result-object v7
  156. invoke-static {v1, v2, v7}, Lokhttp3/internal/http/HttpHeaders;->receiveHeaders(Lokhttp3/CookieJar;Lokhttp3/HttpUrl;Lokhttp3/Headers;)V
  157. invoke-virtual {p1}, Lokhttp3/Response;->newBuilder()Lokhttp3/Response$Builder;
  158. move-result-object v1
  159. invoke-virtual {v1, v0}, Lokhttp3/Response$Builder;->request(Lokhttp3/Request;)Lokhttp3/Response$Builder;
  160. move-result-object v0
  161. if-eqz v8, :cond_8
  162. const-string v1, "Content-Encoding"
  163. invoke-virtual {p1, v1}, Lokhttp3/Response;->header(Ljava/lang/String;)Ljava/lang/String;
  164. move-result-object v2
  165. invoke-virtual {v9, v2}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z
  166. move-result v2
  167. if-eqz v2, :cond_8
  168. invoke-static {p1}, Lokhttp3/internal/http/HttpHeaders;->hasBody(Lokhttp3/Response;)Z
  169. move-result v2
  170. if-eqz v2, :cond_8
  171. new-instance v2, Lokio/GzipSource;
  172. invoke-virtual {p1}, Lokhttp3/Response;->body()Lokhttp3/ResponseBody;
  173. move-result-object v7
  174. invoke-virtual {v7}, Lokhttp3/ResponseBody;->source()Lokio/BufferedSource;
  175. move-result-object v7
  176. invoke-direct {v2, v7}, Lokio/GzipSource;-><init>(Lokio/Source;)V
  177. invoke-virtual {p1}, Lokhttp3/Response;->headers()Lokhttp3/Headers;
  178. move-result-object v7
  179. invoke-virtual {v7}, Lokhttp3/Headers;->newBuilder()Lokhttp3/Headers$Builder;
  180. move-result-object v7
  181. invoke-virtual {v7, v1}, Lokhttp3/Headers$Builder;->removeAll(Ljava/lang/String;)Lokhttp3/Headers$Builder;
  182. move-result-object v1
  183. invoke-virtual {v1, v6}, Lokhttp3/Headers$Builder;->removeAll(Ljava/lang/String;)Lokhttp3/Headers$Builder;
  184. move-result-object v1
  185. invoke-virtual {v1}, Lokhttp3/Headers$Builder;->build()Lokhttp3/Headers;
  186. move-result-object v1
  187. invoke-virtual {v0, v1}, Lokhttp3/Response$Builder;->headers(Lokhttp3/Headers;)Lokhttp3/Response$Builder;
  188. invoke-virtual {p1, v3}, Lokhttp3/Response;->header(Ljava/lang/String;)Ljava/lang/String;
  189. move-result-object p1
  190. new-instance v1, Lokhttp3/internal/http/RealResponseBody;
  191. invoke-static {v2}, Lokio/Okio;->buffer(Lokio/Source;)Lokio/BufferedSource;
  192. move-result-object v2
  193. invoke-direct {v1, p1, v4, v5, v2}, Lokhttp3/internal/http/RealResponseBody;-><init>(Ljava/lang/String;JLokio/BufferedSource;)V
  194. invoke-virtual {v0, v1}, Lokhttp3/Response$Builder;->body(Lokhttp3/ResponseBody;)Lokhttp3/Response$Builder;
  195. :cond_8
  196. invoke-virtual {v0}, Lokhttp3/Response$Builder;->build()Lokhttp3/Response;
  197. move-result-object p1
  198. return-object p1
  199. .end method