Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

367 рядки
21 KiB

20 роки тому
20 роки тому
15 роки тому
15 роки тому
20 роки тому
15 роки тому
17 роки тому
18 роки тому
15 роки тому
15 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
20 роки тому
  1. ibrowse is a HTTP client. The following are a list of features.
  2. - RFC2616 compliant (AFAIK)
  3. - supports GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE,
  4. MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, MOVE and COPY
  5. - Understands HTTP/0.9, HTTP/1.0 and HTTP/1.1
  6. - Understands chunked encoding
  7. - Can generate requests using Chunked Transfer-Encoding
  8. - Pools of connections to each webserver
  9. - Pipelining support
  10. - Download to file
  11. - Asynchronous requests. Responses are streamed to a process
  12. - Basic authentication
  13. - Supports proxy authentication
  14. - Can talk to Secure webservers using SSL
  15. - any other features in the code not listed here :)
  16. ibrowse is available under two different licenses. LGPL or the BSD license.
  17. Comments to : Chandrashekhar.Mullaparthi@gmail.com
  18. Version : 1.6.0
  19. Latest version : git://github.com/cmullaparthi/ibrowse.git
  20. CONTRIBUTIONS & CHANGE HISTORY
  21. ==============================
  22. 12-05-2010 - * Added support for the CONNECT method to tunnel HTTPS through
  23. a proxy. When a https URL is requested through a proxy,
  24. ibrowse will automatically use the CONNECT method to first
  25. setup a tunnel through the proxy. Once this succeeds, the
  26. actual request is dispatched. Successfully tested with the
  27. new SSL implementation in R13B-03
  28. * Added SSL support for direct connections.
  29. See ibrowse:spawn_worker_process/1 and
  30. ibrowse:spawn_link_worker_process/1
  31. * Added option to return raw status line and raw unparsed headers
  32. 23-04-2010 - * Fixes to URL parsing by Karol Skocik
  33. 08-11-2009 - * Added option headers_as_is
  34. 04-10-2009 - * Patch from Kostis Sagonas to cleanup some code and suppress
  35. dialyzer warnings
  36. 24-09-2009 - * When a filename was supplied with the 'save_response_to_file'
  37. option, the option was being ignored. Bug report from
  38. Adam Kocoloski
  39. 05-09-2009 - * Introduced option to allow caller to set socket options.
  40. 29-07-2009 - * The ETS table created for load balancing of requests was not
  41. being deleted which led to the node not being able to create
  42. any more ETS tables if queries were made to many number of
  43. webservers. ibrowse now deletes the ETS table it creates once the
  44. last connection to a webserver is dropped.
  45. Reported by Seth Falcon.
  46. * Spurious data being returned at end of body in certain cases of
  47. chunked encoded responses from the server.
  48. Reported by Chris Newcombe.
  49. 03-07-2009 - Added option {stream_to, {Pid, once}} which allows the caller
  50. to control when it wants to receive more data. If this option
  51. is used, the call ibrowse:stream_next(Req_id) should be used
  52. to get more data.
  53. - Patch submitted by Steve Vinoski to remove compiler warnings
  54. about the use of obsolete guards
  55. 29-06-2009 - * Fixed following issues reported by Oscar Hellstr�m
  56. - Use {active, once} instead of {active, true}
  57. - Fix 'dodgy' timeout handling
  58. - Use binaries internally instead of lists to reduce memory
  59. consumption on 64 bit platforms. The default response format
  60. is still 'list' to maintain backwards compatibility. Use the
  61. option {response_format, binary} to get responses as binaries.
  62. * Fixed chunking bug (reported by Adam Kocoloski)
  63. * Added new option {inactivity_timeout, Milliseconds} to timeout
  64. requests if no data is received on the link for the specified
  65. interval. Useful when responses are large and links are flaky.
  66. * Added ibrowse:all_trace_off/0 to turn off all tracing
  67. * Change to the way responses to asynchronous requests are
  68. returned. The following messages have been removed.
  69. * {ibrowse_async_response, Req_id, {chunk_start, Chunk_size}}
  70. * {ibrowse_async_response, Req_id, chunk_end}
  71. * Fixed Makefiles as part of Debian packaging
  72. (thanks to Thomas Lindgren)
  73. * Moved repository from Sourceforge to Github
  74. 11-06-2009 - * Added option to control size of streamed chunks. Also added
  75. option for the client to receive responses in binary format.
  76. 21-05-2008 - * Fixed bug in reading some options from the ibrowse.conf file.
  77. Reported by Erik Reitsma on the erlyaws mailing list
  78. * Fixed bug when cleaning up closing connections
  79. 27-03-2008 - * Major rewrite of the load balancing feature. Additional module,
  80. ibrowse_lb.erl, introduced to achieve this.
  81. * Can now get a handle to a connection process which is not part of
  82. the load balancing pool. Useful when an application is making
  83. requests to a webserver which are time consuming (such as
  84. uploading a large file). Such requests can be put on a separate
  85. connection, and all other smaller/quicker requests can use the
  86. load balancing pool. See ibrowse:spawn_worker_process/2 and
  87. ibrowse:spawn_link_worker_process/2
  88. * Ram Krishnan sent a patch to enable a client to send a lot of
  89. data in a request by providing a fun which is invoked by the
  90. connection handling process. This fun can fetch the data from
  91. any where. This is useful when trying to upload a large file
  92. to a webserver.
  93. * Use the TCP_NODELAY option on every socket by default
  94. * Rudimentary support for load testing of ibrowse. Undocumented,
  95. but see ibrowse_test:load_test/3. Use the source, Luke!
  96. * New function ibrowse:show_dest_status/2 to view state of
  97. connections/pipelines to a web server
  98. 20-02-2008 - Ram Krishnan sent another patch for another hidden bug in the
  99. save_response_to_file feature.
  100. 07-02-2008 - Ram Krishnan (kriyative _at_ gmail dot com) sent a simple patch to
  101. enable specifying the filename in the save_response_to_file option.
  102. When testing the patch, I realised that my original implementation
  103. of this feature was quite flaky and a lot of corner cases were
  104. not covered. Fixed all of them. Thanks Ram!
  105. 17-10-2007 - Matthew Reilly (matthew dot reilly _at_ sipphone dot com)
  106. sent a bug report and a fix. If the chunk trailer spans two TCP
  107. packets, then ibrowse fails to recognise that the chunked transfer
  108. has ended.
  109. 29-08-2007 - Bug report by Peter Kristensen(ptx _at_ daimi dot au dot dk).
  110. ibrowse crashes when the webserver returns just the Status line
  111. and nothing else.
  112. 28-06-2007 - Added host_header option to enable connection to secure sites
  113. via stunnel
  114. 20-04-2007 - Geoff Cant sent a patch to remove URL encoding for digits in
  115. ibrowse_lib:url_encode/1.
  116. ibrowse had a dependency on the inets application because the
  117. ibrowse_http_client.erl invoked httpd_util:encode_base64/1. This
  118. dependency is now removed and the encode_base64/1 has been
  119. implemented in ibrowse_lib.erl
  120. 06-03-2007 - Eric Merritt sent a patch to support WebDAV requests.
  121. 12-01-2007 - Derek Upham sent in a bug fix. The reset_state function was not
  122. behaving correctly when the transfer encoding was not chunked.
  123. 13-11-2006 - Youn�s Hafri reported a bug where ibrowse was not returning the
  124. temporary filename when the server was closing the connection
  125. after sending the data (as in HTTP/1.0).
  126. Released ibrowse under the BSD license
  127. 12-10-2006 - Chris Newcombe reported bug in dealing with requests where no
  128. body is expected in the response. The first request would succeed
  129. and the next request would hang.
  130. 24-May-2006 - Sean Hinde reported a bug. Async responses with pipelining was
  131. returning the wrong result.
  132. 08-Dec-2005 - Richard Cameron (camster@citeulike.org). Patch to ibrowse to
  133. prevent port number being included in the Host header when port
  134. 80 is intended.
  135. 22-Nov-2005 - Added ability to generate requests using the Chunked
  136. Transfer-Encoding.
  137. 08-May-2005 - Youn�s Hafri made a CRUX LINUX port of ibrowse.
  138. http://yhafri.club.fr/crux/index.html
  139. Here are some usage examples. Enjoy!
  140. 5> ibrowse:start().
  141. {ok,<0.94.0>}
  142. %% A simple GET
  143. 6> ibrowse:send_req("http://intranet/messenger/", [], get).
  144. {ok,"200",
  145. [{"Server","Microsoft-IIS/5.0"},
  146. {"Content-Location","http://intranet/messenger/index.html"},
  147. {"Date","Fri, 17 Dec 2004 15:16:19 GMT"},
  148. {"Content-Type","text/html"},
  149. {"Accept-Ranges","bytes"},
  150. {"Last-Modified","Fri, 17 Dec 2004 08:38:21 GMT"},
  151. {"Etag","\"aa7c9dc313e4c41:d77\""},
  152. {"Content-Length","953"}],
  153. "<html>\r\n\r\n<head>\r\n<title>Messenger</title>\r\n<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 5.0\">\r\n<meta name=\"ProgId\" content=\"FrontPage.Editor.Document\">\r\n<meta name=\"description\" content=\"Messenger Home Page\">\r\n</head>\r\n\r\n<frameset border=\"0\" frameborder=\"0\" rows=\"60,*\">\r\n <frame src=\"/messenger/images/topnav.html\" name=\"mFrameTopNav\" scrolling=\"NO\" target=\"mFrameMain\">\r\n <frameset cols=\"18%,*\">\r\n <frameset rows=\"*,120\">\r\n <frame src=\"index-toc.html\" name=\"mFrameTOC\" target=\"mFrameMain\" scrolling=\"auto\" noresize=\"true\">\r\n <frame src=\"/shared/search/namesearch.html\" name=\"mFrameNameSearch\" scrolling=\"NO\" target=\"mFrameMain\">\r\n </frameset>\r\n <frame src=\"home/16-12-04-xmascardsmms.htm\" name=\"mFrameMain\" scrolling=\"auto\" target=\"mFrameMain\" id=\"mFrameMain\">\r\n </frameset>\r\n <noframes>\r\n <body>\r\n\r\n <p><i>This site requires a browser that can view frames.</i></p>\r\n\r\n </body>\r\n </noframes>\r\n</frameset>\r\n\r\n</html>"}
  154. %% =============================================================================
  155. %% A GET using a proxy
  156. 7> ibrowse:send_req("http://www.google.com/", [], get, [],
  157. [{proxy_user, "XXXXX"},
  158. {proxy_password, "XXXXX"},
  159. {proxy_host, "proxy"},
  160. {proxy_port, 8080}], 1000).
  161. {ok,"302",
  162. [{"Date","Fri, 17 Dec 2004 15:22:56 GMT"},
  163. {"Content-Length","217"},
  164. {"Content-Type","text/html"},
  165. {"Set-Cookie",
  166. "PREF=ID=f58155c797f96096:CR=1:TM=1103296999:LM=1103296999:S=FiWdtAqQvhQ0TvHq; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"},
  167. {"Server","GWS/2.1"},
  168. {"Location",
  169. "http://www.google.co.uk/cxfer?c=PREF%3D:TM%3D1103296999:S%3Do8bEY2FIHwdyGenS&prev=/"},
  170. {"Via","1.1 netapp01 (NetCache NetApp/5.5R2)"}],
  171. "<HTML><HEAD><TITLE>302 Moved</TITLE></HEAD><BODY>\n<H1>302 Moved</H1>\nThe document has moved\n<A HREF=\"http://www.google.co.uk/cxfer?c=PREF%3D:TM%3D1103296999:S%3Do8bEY2FIHwdyGenS&amp;prev=/\">here</A>.\r\n</BODY></HTML>\r\n"}
  172. %% =============================================================================
  173. %% A GET response saved to file. A temporary file is created and the
  174. %% filename returned. The response will only be saved to file is the
  175. %% status code is in the 200 range. The directory to download to can
  176. %% be set using the application env var 'download_dir' - the default
  177. %% is the current working directory.
  178. 8> ibrowse:send_req("http://www.erlang.se/", [], get, [],
  179. [{proxy_user, "XXXXX"},
  180. {proxy_password, "XXXXX"},
  181. {proxy_host, "proxy"},
  182. {proxy_port, 8080},
  183. {save_response_to_file, true}], 1000).
  184. {error,req_timedout}
  185. %% =============================================================================
  186. 9> ibrowse:send_req("http://www.erlang.se/", [], get, [],
  187. [{proxy_user, "XXXXX"},
  188. {proxy_password, "XXXXX"},
  189. {proxy_host, "proxy"},
  190. {proxy_port, 8080},
  191. {save_response_to_file, true}], 5000).
  192. {ok,"200",
  193. [{"Transfer-Encoding","chunked"},
  194. {"Date","Fri, 17 Dec 2004 15:24:36 GMT"},
  195. {"Content-Type","text/html"},
  196. {"Server","Apache/1.3.9 (Unix)"},
  197. {"Via","1.1 netapp01 (NetCache NetApp/5.5R2)"}],
  198. {file,"/Users/chandru/code/ibrowse/src/ibrowse_tmp_file_1103297041125854"}}
  199. %% =============================================================================
  200. %% Setting size of connection pool and pipeline size. This sets the
  201. %% number of maximum connections to this server to 10 and the pipeline
  202. %% size to 1. Connections are setup a required.
  203. 11> ibrowse:set_dest("www.hotmail.com", 80, [{max_sessions, 10},
  204. {max_pipeline_size, 1}]).
  205. ok
  206. %% =============================================================================
  207. %% Example using the HEAD method
  208. 56> ibrowse:send_req("http://www.erlang.org", [], head).
  209. {ok,"200",
  210. [{"Date","Mon, 28 Feb 2005 04:40:53 GMT"},
  211. {"Server","Apache/1.3.9 (Unix)"},
  212. {"Last-Modified","Thu, 10 Feb 2005 09:31:23 GMT"},
  213. {"Etag","\"8d71d-1efa-420b29eb\""},
  214. {"Accept-ranges","bytes"},
  215. {"Content-Length","7930"},
  216. {"Content-Type","text/html"}],
  217. []}
  218. %% =============================================================================
  219. %% Example using the OPTIONS method
  220. 62> ibrowse:send_req("http://www.sun.com", [], options).
  221. {ok,"200",
  222. [{"Server","Sun Java System Web Server 6.1"},
  223. {"Date","Mon, 28 Feb 2005 04:44:39 GMT"},
  224. {"Content-Length","0"},
  225. {"P3p",
  226. "policyref=\"http://www.sun.com/p3p/Sun_P3P_Policy.xml\", CP=\"CAO DSP COR CUR ADMa DEVa TAIa PSAa PSDa CONi TELi OUR SAMi PUBi IND PHY ONL PUR COM NAV INT DEM CNT STA POL PRE GOV\""},
  227. {"Set-Cookie",
  228. "SUN_ID=X.X.X.X:169191109565879; EXPIRES=Wednesday, 31-Dec-2025 23:59:59 GMT; DOMAIN=.sun.com; PATH=/"},
  229. {"Allow",
  230. "HEAD, GET, PUT, POST, DELETE, TRACE, OPTIONS, MOVE, INDEX, MKDIR, RMDIR"}],
  231. []}
  232. %% =============================================================================
  233. %% Example of using Asynchronous requests
  234. 18> ibrowse:send_req("http://www.google.com", [], get, [],
  235. [{proxy_user, "XXXXX"},
  236. {proxy_password, "XXXXX"},
  237. {proxy_host, "proxy"},
  238. {proxy_port, 8080},
  239. {stream_to, self()}]).
  240. {ibrowse_req_id,{1115,327256,389608}}
  241. 19> flush().
  242. Shell got {ibrowse_async_headers,{1115,327256,389608},
  243. "302",
  244. [{"Date","Thu, 05 May 2005 21:06:41 GMT"},
  245. {"Content-Length","217"},
  246. {"Content-Type","text/html"},
  247. {"Set-Cookie",
  248. "PREF=ID=b601f16bfa32f071:CR=1:TM=1115327201:LM=1115327201:S=OX5hSB525AMjUUu7; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"},
  249. {"Server","GWS/2.1"},
  250. {"Location",
  251. "http://www.google.co.uk/cxfer?c=PREF%3D:TM%3D1115327201:S%3DDS9pDJ4IHcAuZ_AS&prev=/"},
  252. {"Via",
  253. "1.1 hatproxy01 (NetCache NetApp/5.6.2)"}]}
  254. Shell got {ibrowse_async_response,{1115,327256,389608},
  255. "<HTML><HEAD><TITLE>302 Moved</TITLE></HEAD><BODY>\n<H1>302 Moved</H1>\nThe document has moved\n<A HREF=\"http://www.google.co.uk/cxfer?c=PREF%3D:TM%3D1115327201:S%3DDS9pDJ4IHcAuZ_AS&amp;prev=/\">here</A>.\r\n</BODY></HTML>\r\n"}
  256. Shell got {ibrowse_async_response_end,{1115,327256,389608}}
  257. ok
  258. %% =============================================================================
  259. %% Another example of using async requests
  260. 24> ibrowse:send_req("http://yaws.hyber.org/simple_ex2.yaws", [], get, [],
  261. [{proxy_user, "XXXXX"},
  262. {proxy_password, "XXXXX"},
  263. {proxy_host, "proxy"},
  264. {proxy_port, 8080},
  265. {stream_to, self()}]).
  266. {ibrowse_req_id,{1115,327430,512314}}
  267. 25> flush().
  268. Shell got {ibrowse_async_headers,{1115,327430,512314},
  269. "200",
  270. [{"Date","Thu, 05 May 2005 20:58:08 GMT"},
  271. {"Content-Length","64"},
  272. {"Content-Type","text/html;charset="},
  273. {"Server",
  274. "Yaws/1.54 Yet Another Web Server"},
  275. {"Via",
  276. "1.1 hatproxy01 (NetCache NetApp/5.6.2)"}]}
  277. Shell got {ibrowse_async_response,{1115,327430,512314},
  278. "<html>\n\n\n<h1> Yesssssss </h1>\n\n<h2> Hello again </h2>\n\n\n</html>\n"}
  279. Shell got {ibrowse_async_response_end,{1115,327430,512314}}
  280. %% =============================================================================
  281. %% Example of request which fails when using the async option. Here
  282. %% the {ibrowse_req_id, ReqId} is not returned. Instead the error code is
  283. %% returned.
  284. 68> ibrowse:send_req("http://www.earlyriser.org", [], get, [], [{stream_to, self()}]).
  285. {error,conn_failed}
  286. %% Example of request using both Proxy-Authorization and authorization by the final webserver.
  287. 17> ibrowse:send_req("http://www.erlang.se/lic_area/protected/patches/erl_756_otp_beam.README",
  288. [], get, [],
  289. [{proxy_user, "XXXXX"},
  290. {proxy_password, "XXXXX"},
  291. {proxy_host, "proxy"},
  292. {proxy_port, 8080},
  293. {basic_auth, {"XXXXX", "XXXXXX"}}]).
  294. {ok,"200",
  295. [{"Accept-Ranges","bytes"},
  296. {"Date","Thu, 05 May 2005 21:02:09 GMT"},
  297. {"Content-Length","2088"},
  298. {"Content-Type","text/plain"},
  299. {"Server","Apache/1.3.9 (Unix)"},
  300. {"Last-Modified","Tue, 03 May 2005 15:08:18 GMT"},
  301. {"ETag","\"1384c8-828-427793e2\""},
  302. {"Via","1.1 hatproxy01 (NetCache NetApp/5.6.2)"}],
  303. "Patch Id:\t\terl_756_otp_beam\nLabel:\t\t\tinets patch\nDate:\t\t\t2005-05-03\nTrouble Report Id:\tOTP-5513, OTP-5514, OTP-5516, OTP-5517, OTP-5521, OTP-5537\nSeq num:\t\tseq9806\nSystem:\t\t\totp\nRelease:\t\tR10B\nOperating System:\tall\nArchitecture:\t\tall\nErlang machine:\t\tBEAM\nApplication:\t\tinets-4.4\nFiles:\t\t\tall\n\nDescription:\n\n OTP-5513 The server did not handle HTTP-0.9 messages with an implicit\n\t version.\n\n OTP-5514 An internal server timeout killed the request handling\n\t process without sending a message back to the client. As this\n\t timeout only affects a single request it has been set to\n\t infinity (if the main server process dies the request\n\t handling process will also die and the client will receive an\n\t error). This might make a client that does not use a timeout\n\t hang for a longer period of time, but that is an expected\n\t behavior!\n\n OTP-5516 That a third party closes the http servers accept socket is\n\t recoverable for inets, hence intes will only produce an info\n\t report as there was no error in inets but measures where\n\t taken to avoid failure due to errors elsewhere.\n\n OTP-5517 The HTTP client proxy settings where ignored. Bug introduced\n\t in inets-4.3.\n\n OTP-5521 Inets only sent the \"WWW-Authenticate\" header at the first\n\t attempt to get a page, if the user supplied the wrong\n\t user/password combination the header was not sent again. This\n\t forces the user to kill the browser entirely after a failed\n\t login attempt, before the user may try to login again. Inets\n\t now always send the authentication header.\n\n OTP-5537 A major rewrite of big parts of the HTTP server code was\n\t performed. There where many things that did not work\n\t satisfactory. Cgi script handling can never have worked\n\t properly and the cases when it did sort of work, a big\n\t unnecessary delay was enforced. Headers where not always\n\t treated as expected and HTTP version handling did not work,\n\t all responses where sent as version HTTP/1.1 no matter what.\n\n\n"}
  304. %% =============================================================================
  305. %% Example of a TRACE request. Very interesting! yaws.hyber.org didn't
  306. %% support this. Nor did www.google.com. But good old BBC supports
  307. %% this.
  308. 35> 37> ibrowse:send_req("http://www.bbc.co.uk/", [], trace, [],
  309. [{proxy_user, "XXXXX"},
  310. {proxy_password, "XXXXX"},
  311. {proxy_host, "proxy"},
  312. {proxy_port, 8080}]).
  313. {ok,"200",
  314. [{"Transfer-Encoding","chunked"},
  315. {"Date","Thu, 05 May 2005 21:40:27 GMT"},
  316. {"Content-Type","message/http"},
  317. {"Server","Apache/2.0.51 (Unix)"},
  318. {"Set-Cookie",
  319. "BBC-UID=7452e72a29424c5b0b232c7131c7d9395d209b7170e8604072e0fcb3630467300; expires=Mon, 04-May-09 21:40:27 GMT; path=/; domain=bbc.co.uk;"},
  320. {"Set-Cookie",
  321. "BBC-UID=7452e72a29424c5b0b232c7131c7d9395d209b7170e8604072e0fcb3630467300; expires=Mon, 04-May-09 21:40:27 GMT; path=/; domain=bbc.co.uk;"},
  322. {"Via","1.1 hatproxy01 (NetCache NetApp/5.6.2)"}],
  323. "TRACE / HTTP/1.1\r\nHost: www.bbc.co.uk\r\nConnection: keep-alive\r\nX-Forwarded-For: 172.24.28.29\r\nVia: 1.1 hatproxy01 (NetCache NetApp/5.6.2)\r\nCookie: BBC-UID=7452e72a29424c5b0b232c7131c7d9395d209b7170e8604072e0fcb3630467300\r\n\r\n"}