Http2Server.smali 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. .class public final Lokhttp3/internal/http2/Http2Server;
  2. .super Lokhttp3/internal/http2/Http2Connection$Listener;
  3. .source ""
  4. # static fields
  5. .field static final logger:Ljava/util/logging/Logger;
  6. # instance fields
  7. .field private final baseDirectory:Ljava/io/File;
  8. .field private final sslSocketFactory:Ljavax/net/ssl/SSLSocketFactory;
  9. # direct methods
  10. .method static constructor <clinit>()V
  11. .locals 1
  12. const-class v0, Lokhttp3/internal/http2/Http2Server;
  13. invoke-virtual {v0}, Ljava/lang/Class;->getName()Ljava/lang/String;
  14. move-result-object v0
  15. invoke-static {v0}, Ljava/util/logging/Logger;->getLogger(Ljava/lang/String;)Ljava/util/logging/Logger;
  16. move-result-object v0
  17. sput-object v0, Lokhttp3/internal/http2/Http2Server;->logger:Ljava/util/logging/Logger;
  18. return-void
  19. .end method
  20. .method public constructor <init>(Ljava/io/File;Ljavax/net/ssl/SSLSocketFactory;)V
  21. .locals 0
  22. invoke-direct {p0}, Lokhttp3/internal/http2/Http2Connection$Listener;-><init>()V
  23. iput-object p1, p0, Lokhttp3/internal/http2/Http2Server;->baseDirectory:Ljava/io/File;
  24. iput-object p2, p0, Lokhttp3/internal/http2/Http2Server;->sslSocketFactory:Ljavax/net/ssl/SSLSocketFactory;
  25. return-void
  26. .end method
  27. .method private contentType(Ljava/io/File;)Ljava/lang/String;
  28. .locals 3
  29. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  30. move-result-object v0
  31. const-string v1, ".css"
  32. invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  33. move-result v0
  34. if-eqz v0, :cond_0
  35. const-string p1, "text/css"
  36. return-object p1
  37. :cond_0
  38. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  39. move-result-object v0
  40. const-string v1, ".gif"
  41. invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  42. move-result v0
  43. if-eqz v0, :cond_1
  44. const-string p1, "image/gif"
  45. return-object p1
  46. :cond_1
  47. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  48. move-result-object v0
  49. const-string v1, ".html"
  50. invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  51. move-result v0
  52. if-eqz v0, :cond_2
  53. const-string p1, "text/html"
  54. return-object p1
  55. :cond_2
  56. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  57. move-result-object v0
  58. const-string v1, ".jpeg"
  59. invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  60. move-result v0
  61. const-string v1, "image/jpeg"
  62. if-eqz v0, :cond_3
  63. return-object v1
  64. :cond_3
  65. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  66. move-result-object v0
  67. const-string v2, ".jpg"
  68. invoke-virtual {v0, v2}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  69. move-result v0
  70. if-eqz v0, :cond_4
  71. return-object v1
  72. :cond_4
  73. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  74. move-result-object v0
  75. const-string v1, ".js"
  76. invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  77. move-result v0
  78. if-eqz v0, :cond_5
  79. const-string p1, "application/javascript"
  80. return-object p1
  81. :cond_5
  82. invoke-virtual {p1}, Ljava/io/File;->getName()Ljava/lang/String;
  83. move-result-object p1
  84. const-string v0, ".png"
  85. invoke-virtual {p1, v0}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
  86. move-result p1
  87. if-eqz p1, :cond_6
  88. const-string p1, "image/png"
  89. return-object p1
  90. :cond_6
  91. const-string p1, "text/plain"
  92. return-object p1
  93. .end method
  94. .method private doSsl(Ljava/net/Socket;)Ljavax/net/ssl/SSLSocket;
  95. .locals 4
  96. .annotation system Ldalvik/annotation/Throws;
  97. value = {
  98. Ljava/io/IOException;
  99. }
  100. .end annotation
  101. iget-object v0, p0, Lokhttp3/internal/http2/Http2Server;->sslSocketFactory:Ljavax/net/ssl/SSLSocketFactory;
  102. invoke-virtual {p1}, Ljava/net/Socket;->getInetAddress()Ljava/net/InetAddress;
  103. move-result-object v1
  104. invoke-virtual {v1}, Ljava/net/InetAddress;->getHostAddress()Ljava/lang/String;
  105. move-result-object v1
  106. invoke-virtual {p1}, Ljava/net/Socket;->getPort()I
  107. move-result v2
  108. const/4 v3, 0x1
  109. invoke-virtual {v0, p1, v1, v2, v3}, Ljavax/net/ssl/SSLSocketFactory;->createSocket(Ljava/net/Socket;Ljava/lang/String;IZ)Ljava/net/Socket;
  110. move-result-object p1
  111. check-cast p1, Ljavax/net/ssl/SSLSocket;
  112. const/4 v0, 0x0
  113. invoke-virtual {p1, v0}, Ljavax/net/ssl/SSLSocket;->setUseClientMode(Z)V
  114. invoke-static {}, Lokhttp3/internal/platform/Platform;->get()Lokhttp3/internal/platform/Platform;
  115. move-result-object v0
  116. sget-object v1, Lokhttp3/Protocol;->HTTP_2:Lokhttp3/Protocol;
  117. invoke-static {v1}, Ljava/util/Collections;->singletonList(Ljava/lang/Object;)Ljava/util/List;
  118. move-result-object v1
  119. const/4 v2, 0x0
  120. invoke-virtual {v0, p1, v2, v1}, Lokhttp3/internal/platform/Platform;->configureTlsExtensions(Ljavax/net/ssl/SSLSocket;Ljava/lang/String;Ljava/util/List;)V
  121. invoke-virtual {p1}, Ljavax/net/ssl/SSLSocket;->startHandshake()V
  122. return-object p1
  123. .end method
  124. .method public static varargs main([Ljava/lang/String;)V
  125. .locals 3
  126. .annotation system Ldalvik/annotation/Throws;
  127. value = {
  128. Ljava/lang/Exception;
  129. }
  130. .end annotation
  131. array-length v0, p0
  132. const/4 v1, 0x1
  133. if-ne v0, v1, :cond_1
  134. const/4 v0, 0x0
  135. aget-object v1, p0, v0
  136. const-string v2, "-"
  137. invoke-virtual {v1, v2}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
  138. move-result v1
  139. if-eqz v1, :cond_0
  140. goto :goto_0
  141. :cond_0
  142. new-instance v1, Lokhttp3/internal/http2/Http2Server;
  143. new-instance v2, Ljava/io/File;
  144. aget-object p0, p0, v0
  145. invoke-direct {v2, p0}, Ljava/io/File;-><init>(Ljava/lang/String;)V
  146. invoke-static {}, Lokhttp3/internal/tls/SslClient;->localhost()Lokhttp3/internal/tls/SslClient;
  147. move-result-object p0
  148. iget-object p0, p0, Lokhttp3/internal/tls/SslClient;->sslContext:Ljavax/net/ssl/SSLContext;
  149. invoke-virtual {p0}, Ljavax/net/ssl/SSLContext;->getSocketFactory()Ljavax/net/ssl/SSLSocketFactory;
  150. move-result-object p0
  151. invoke-direct {v1, v2, p0}, Lokhttp3/internal/http2/Http2Server;-><init>(Ljava/io/File;Ljavax/net/ssl/SSLSocketFactory;)V
  152. invoke-direct {v1}, Lokhttp3/internal/http2/Http2Server;->run()V
  153. return-void
  154. :cond_1
  155. :goto_0
  156. sget-object p0, Ljava/lang/System;->out:Ljava/io/PrintStream;
  157. const-string v0, "Usage: Http2Server <base directory>"
  158. invoke-virtual {p0, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
  159. return-void
  160. .end method
  161. .method private run()V
  162. .locals 8
  163. .annotation system Ldalvik/annotation/Throws;
  164. value = {
  165. Ljava/lang/Exception;
  166. }
  167. .end annotation
  168. new-instance v0, Ljava/net/ServerSocket;
  169. const/16 v1, 0x22b8
  170. invoke-direct {v0, v1}, Ljava/net/ServerSocket;-><init>(I)V
  171. const/4 v1, 0x1
  172. invoke-virtual {v0, v1}, Ljava/net/ServerSocket;->setReuseAddress(Z)V
  173. :goto_0
  174. const/4 v1, 0x0
  175. :try_start_0
  176. invoke-virtual {v0}, Ljava/net/ServerSocket;->accept()Ljava/net/Socket;
  177. move-result-object v2
  178. :try_end_0
  179. .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_3
  180. .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_2
  181. :try_start_1
  182. invoke-direct {p0, v2}, Lokhttp3/internal/http2/Http2Server;->doSsl(Ljava/net/Socket;)Ljavax/net/ssl/SSLSocket;
  183. move-result-object v3
  184. invoke-static {}, Lokhttp3/internal/platform/Platform;->get()Lokhttp3/internal/platform/Platform;
  185. move-result-object v4
  186. invoke-virtual {v4, v3}, Lokhttp3/internal/platform/Platform;->getSelectedProtocol(Ljavax/net/ssl/SSLSocket;)Ljava/lang/String;
  187. move-result-object v4
  188. if-eqz v4, :cond_0
  189. invoke-static {v4}, Lokhttp3/Protocol;->get(Ljava/lang/String;)Lokhttp3/Protocol;
  190. move-result-object v1
  191. :cond_0
  192. sget-object v4, Lokhttp3/Protocol;->HTTP_2:Lokhttp3/Protocol;
  193. if-ne v1, v4, :cond_1
  194. new-instance v1, Lokhttp3/internal/http2/Http2Connection$Builder;
  195. const/4 v4, 0x0
  196. invoke-direct {v1, v4}, Lokhttp3/internal/http2/Http2Connection$Builder;-><init>(Z)V
  197. invoke-virtual {v1, v3}, Lokhttp3/internal/http2/Http2Connection$Builder;->socket(Ljava/net/Socket;)Lokhttp3/internal/http2/Http2Connection$Builder;
  198. move-result-object v1
  199. invoke-virtual {v1, p0}, Lokhttp3/internal/http2/Http2Connection$Builder;->listener(Lokhttp3/internal/http2/Http2Connection$Listener;)Lokhttp3/internal/http2/Http2Connection$Builder;
  200. move-result-object v1
  201. invoke-virtual {v1}, Lokhttp3/internal/http2/Http2Connection$Builder;->build()Lokhttp3/internal/http2/Http2Connection;
  202. move-result-object v1
  203. invoke-virtual {v1}, Lokhttp3/internal/http2/Http2Connection;->start()V
  204. goto :goto_0
  205. :cond_1
  206. new-instance v3, Ljava/net/ProtocolException;
  207. new-instance v4, Ljava/lang/StringBuilder;
  208. invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V
  209. const-string v5, "Protocol "
  210. invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  211. invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  212. const-string v1, " unsupported"
  213. invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  214. invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  215. move-result-object v1
  216. invoke-direct {v3, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  217. throw v3
  218. :try_end_1
  219. .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_1
  220. .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0
  221. :catch_0
  222. move-exception v1
  223. goto :goto_1
  224. :catch_1
  225. move-exception v1
  226. goto :goto_2
  227. :catch_2
  228. move-exception v2
  229. move-object v7, v2
  230. move-object v2, v1
  231. move-object v1, v7
  232. :goto_1
  233. sget-object v3, Lokhttp3/internal/http2/Http2Server;->logger:Ljava/util/logging/Logger;
  234. sget-object v4, Ljava/util/logging/Level;->WARNING:Ljava/util/logging/Level;
  235. const-string v5, "Http2Server unexpected failure"
  236. invoke-virtual {v3, v4, v5, v1}, Ljava/util/logging/Logger;->log(Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Throwable;)V
  237. goto :goto_3
  238. :catch_3
  239. move-exception v2
  240. move-object v7, v2
  241. move-object v2, v1
  242. move-object v1, v7
  243. :goto_2
  244. sget-object v3, Lokhttp3/internal/http2/Http2Server;->logger:Ljava/util/logging/Logger;
  245. sget-object v4, Ljava/util/logging/Level;->INFO:Ljava/util/logging/Level;
  246. new-instance v5, Ljava/lang/StringBuilder;
  247. invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V
  248. const-string v6, "Http2Server connection failure: "
  249. invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  250. invoke-virtual {v5, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  251. invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  252. move-result-object v1
  253. invoke-virtual {v3, v4, v1}, Ljava/util/logging/Logger;->log(Ljava/util/logging/Level;Ljava/lang/String;)V
  254. :goto_3
  255. invoke-static {v2}, Lokhttp3/internal/Util;->closeQuietly(Ljava/net/Socket;)V
  256. goto :goto_0
  257. .end method
  258. .method private send404(Lokhttp3/internal/http2/Http2Stream;Ljava/lang/String;)V
  259. .locals 5
  260. .annotation system Ldalvik/annotation/Throws;
  261. value = {
  262. Ljava/io/IOException;
  263. }
  264. .end annotation
  265. const/4 v0, 0x3
  266. new-array v0, v0, [Lokhttp3/internal/http2/Header;
  267. new-instance v1, Lokhttp3/internal/http2/Header;
  268. const-string v2, ":status"
  269. const-string v3, "404"
  270. invoke-direct {v1, v2, v3}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  271. const/4 v2, 0x0
  272. aput-object v1, v0, v2
  273. new-instance v1, Lokhttp3/internal/http2/Header;
  274. const-string v2, ":version"
  275. const-string v3, "HTTP/1.1"
  276. invoke-direct {v1, v2, v3}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  277. const/4 v2, 0x1
  278. aput-object v1, v0, v2
  279. new-instance v1, Lokhttp3/internal/http2/Header;
  280. const-string v3, "content-type"
  281. const-string v4, "text/plain"
  282. invoke-direct {v1, v3, v4}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  283. const/4 v3, 0x2
  284. aput-object v1, v0, v3
  285. invoke-static {v0}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;
  286. move-result-object v0
  287. invoke-virtual {p1, v0, v2}, Lokhttp3/internal/http2/Http2Stream;->sendResponseHeaders(Ljava/util/List;Z)V
  288. invoke-virtual {p1}, Lokhttp3/internal/http2/Http2Stream;->getSink()Lokio/Sink;
  289. move-result-object p1
  290. invoke-static {p1}, Lokio/Okio;->buffer(Lokio/Sink;)Lokio/BufferedSink;
  291. move-result-object p1
  292. new-instance v0, Ljava/lang/StringBuilder;
  293. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  294. const-string v1, "Not found: "
  295. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  296. invoke-virtual {v0, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  297. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  298. move-result-object p2
  299. invoke-interface {p1, p2}, Lokio/BufferedSink;->writeUtf8(Ljava/lang/String;)Lokio/BufferedSink;
  300. invoke-interface {p1}, Lokio/Sink;->close()V
  301. return-void
  302. .end method
  303. .method private serveDirectory(Lokhttp3/internal/http2/Http2Stream;[Ljava/io/File;)V
  304. .locals 6
  305. .annotation system Ldalvik/annotation/Throws;
  306. value = {
  307. Ljava/io/IOException;
  308. }
  309. .end annotation
  310. const/4 v0, 0x3
  311. new-array v0, v0, [Lokhttp3/internal/http2/Header;
  312. new-instance v1, Lokhttp3/internal/http2/Header;
  313. const-string v2, ":status"
  314. const-string v3, "200"
  315. invoke-direct {v1, v2, v3}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  316. const/4 v2, 0x0
  317. aput-object v1, v0, v2
  318. new-instance v1, Lokhttp3/internal/http2/Header;
  319. const-string v3, ":version"
  320. const-string v4, "HTTP/1.1"
  321. invoke-direct {v1, v3, v4}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  322. const/4 v3, 0x1
  323. aput-object v1, v0, v3
  324. new-instance v1, Lokhttp3/internal/http2/Header;
  325. const-string v4, "content-type"
  326. const-string v5, "text/html; charset=UTF-8"
  327. invoke-direct {v1, v4, v5}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  328. const/4 v4, 0x2
  329. aput-object v1, v0, v4
  330. invoke-static {v0}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;
  331. move-result-object v0
  332. invoke-virtual {p1, v0, v3}, Lokhttp3/internal/http2/Http2Stream;->sendResponseHeaders(Ljava/util/List;Z)V
  333. invoke-virtual {p1}, Lokhttp3/internal/http2/Http2Stream;->getSink()Lokio/Sink;
  334. move-result-object p1
  335. invoke-static {p1}, Lokio/Okio;->buffer(Lokio/Sink;)Lokio/BufferedSink;
  336. move-result-object p1
  337. array-length v0, p2
  338. :goto_0
  339. if-ge v2, v0, :cond_1
  340. aget-object v1, p2, v2
  341. invoke-virtual {v1}, Ljava/io/File;->isDirectory()Z
  342. move-result v3
  343. if-eqz v3, :cond_0
  344. new-instance v3, Ljava/lang/StringBuilder;
  345. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  346. invoke-virtual {v1}, Ljava/io/File;->getName()Ljava/lang/String;
  347. move-result-object v1
  348. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  349. const-string v1, "/"
  350. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  351. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  352. move-result-object v1
  353. goto :goto_1
  354. :cond_0
  355. invoke-virtual {v1}, Ljava/io/File;->getName()Ljava/lang/String;
  356. move-result-object v1
  357. :goto_1
  358. new-instance v3, Ljava/lang/StringBuilder;
  359. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  360. const-string v4, "<a href=\'"
  361. invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  362. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  363. const-string v4, "\'>"
  364. invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  365. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  366. const-string v1, "</a><br>"
  367. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  368. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  369. move-result-object v1
  370. invoke-interface {p1, v1}, Lokio/BufferedSink;->writeUtf8(Ljava/lang/String;)Lokio/BufferedSink;
  371. add-int/lit8 v2, v2, 0x1
  372. goto :goto_0
  373. :cond_1
  374. invoke-interface {p1}, Lokio/Sink;->close()V
  375. return-void
  376. .end method
  377. .method private serveFile(Lokhttp3/internal/http2/Http2Stream;Ljava/io/File;)V
  378. .locals 5
  379. .annotation system Ldalvik/annotation/Throws;
  380. value = {
  381. Ljava/io/IOException;
  382. }
  383. .end annotation
  384. const/4 v0, 0x3
  385. new-array v0, v0, [Lokhttp3/internal/http2/Header;
  386. new-instance v1, Lokhttp3/internal/http2/Header;
  387. const-string v2, ":status"
  388. const-string v3, "200"
  389. invoke-direct {v1, v2, v3}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  390. const/4 v2, 0x0
  391. aput-object v1, v0, v2
  392. new-instance v1, Lokhttp3/internal/http2/Header;
  393. const-string v2, ":version"
  394. const-string v3, "HTTP/1.1"
  395. invoke-direct {v1, v2, v3}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  396. const/4 v2, 0x1
  397. aput-object v1, v0, v2
  398. new-instance v1, Lokhttp3/internal/http2/Header;
  399. invoke-direct {p0, p2}, Lokhttp3/internal/http2/Http2Server;->contentType(Ljava/io/File;)Ljava/lang/String;
  400. move-result-object v3
  401. const-string v4, "content-type"
  402. invoke-direct {v1, v4, v3}, Lokhttp3/internal/http2/Header;-><init>(Ljava/lang/String;Ljava/lang/String;)V
  403. const/4 v3, 0x2
  404. aput-object v1, v0, v3
  405. invoke-static {v0}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;
  406. move-result-object v0
  407. invoke-virtual {p1, v0, v2}, Lokhttp3/internal/http2/Http2Stream;->sendResponseHeaders(Ljava/util/List;Z)V
  408. invoke-static {p2}, Lokio/Okio;->source(Ljava/io/File;)Lokio/Source;
  409. move-result-object p2
  410. :try_start_0
  411. invoke-virtual {p1}, Lokhttp3/internal/http2/Http2Stream;->getSink()Lokio/Sink;
  412. move-result-object p1
  413. invoke-static {p1}, Lokio/Okio;->buffer(Lokio/Sink;)Lokio/BufferedSink;
  414. move-result-object p1
  415. invoke-interface {p1, p2}, Lokio/BufferedSink;->writeAll(Lokio/Source;)J
  416. invoke-interface {p1}, Lokio/Sink;->close()V
  417. :try_end_0
  418. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  419. invoke-static {p2}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  420. return-void
  421. :catchall_0
  422. move-exception p1
  423. invoke-static {p2}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  424. throw p1
  425. .end method
  426. # virtual methods
  427. .method public onStream(Lokhttp3/internal/http2/Http2Stream;)V
  428. .locals 6
  429. .annotation system Ldalvik/annotation/Throws;
  430. value = {
  431. Ljava/io/IOException;
  432. }
  433. .end annotation
  434. const/4 v0, 0x0
  435. :try_start_0
  436. invoke-virtual {p1}, Lokhttp3/internal/http2/Http2Stream;->getRequestHeaders()Ljava/util/List;
  437. move-result-object v1
  438. const/4 v2, 0x0
  439. invoke-interface {v1}, Ljava/util/List;->size()I
  440. move-result v3
  441. :goto_0
  442. if-ge v2, v3, :cond_1
  443. invoke-interface {v1, v2}, Ljava/util/List;->get(I)Ljava/lang/Object;
  444. move-result-object v4
  445. check-cast v4, Lokhttp3/internal/http2/Header;
  446. iget-object v4, v4, Lokhttp3/internal/http2/Header;->name:Lokio/ByteString;
  447. sget-object v5, Lokhttp3/internal/http2/Header;->TARGET_PATH:Lokio/ByteString;
  448. invoke-virtual {v4, v5}, Lokio/ByteString;->equals(Ljava/lang/Object;)Z
  449. move-result v4
  450. if-eqz v4, :cond_0
  451. invoke-interface {v1, v2}, Ljava/util/List;->get(I)Ljava/lang/Object;
  452. move-result-object v1
  453. check-cast v1, Lokhttp3/internal/http2/Header;
  454. iget-object v1, v1, Lokhttp3/internal/http2/Header;->value:Lokio/ByteString;
  455. invoke-virtual {v1}, Lokio/ByteString;->utf8()Ljava/lang/String;
  456. move-result-object v1
  457. goto :goto_1
  458. :cond_0
  459. add-int/lit8 v2, v2, 0x1
  460. goto :goto_0
  461. :cond_1
  462. move-object v1, v0
  463. :goto_1
  464. if-eqz v1, :cond_4
  465. new-instance v2, Ljava/io/File;
  466. new-instance v3, Ljava/lang/StringBuilder;
  467. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  468. iget-object v4, p0, Lokhttp3/internal/http2/Http2Server;->baseDirectory:Ljava/io/File;
  469. invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  470. invoke-virtual {v3, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  471. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  472. move-result-object v3
  473. invoke-direct {v2, v3}, Ljava/io/File;-><init>(Ljava/lang/String;)V
  474. invoke-virtual {v2}, Ljava/io/File;->isDirectory()Z
  475. move-result v3
  476. if-eqz v3, :cond_2
  477. invoke-virtual {v2}, Ljava/io/File;->listFiles()[Ljava/io/File;
  478. move-result-object v1
  479. invoke-direct {p0, p1, v1}, Lokhttp3/internal/http2/Http2Server;->serveDirectory(Lokhttp3/internal/http2/Http2Stream;[Ljava/io/File;)V
  480. goto :goto_2
  481. :cond_2
  482. invoke-virtual {v2}, Ljava/io/File;->exists()Z
  483. move-result v3
  484. if-eqz v3, :cond_3
  485. invoke-direct {p0, p1, v2}, Lokhttp3/internal/http2/Http2Server;->serveFile(Lokhttp3/internal/http2/Http2Stream;Ljava/io/File;)V
  486. goto :goto_2
  487. :cond_3
  488. invoke-direct {p0, p1, v1}, Lokhttp3/internal/http2/Http2Server;->send404(Lokhttp3/internal/http2/Http2Stream;Ljava/lang/String;)V
  489. goto :goto_2
  490. :cond_4
  491. new-instance p1, Ljava/lang/AssertionError;
  492. invoke-direct {p1}, Ljava/lang/AssertionError;-><init>()V
  493. throw p1
  494. :try_end_0
  495. .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
  496. :catch_0
  497. move-exception p1
  498. invoke-static {}, Lokhttp3/internal/platform/Platform;->get()Lokhttp3/internal/platform/Platform;
  499. move-result-object v1
  500. const/4 v2, 0x4
  501. new-instance v3, Ljava/lang/StringBuilder;
  502. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  503. const-string v4, "Failure serving Http2Stream: "
  504. invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  505. invoke-virtual {p1}, Ljava/io/IOException;->getMessage()Ljava/lang/String;
  506. move-result-object p1
  507. invoke-virtual {v3, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  508. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  509. move-result-object p1
  510. invoke-virtual {v1, v2, p1, v0}, Lokhttp3/internal/platform/Platform;->log(ILjava/lang/String;Ljava/lang/Throwable;)V
  511. :goto_2
  512. return-void
  513. .end method