Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

229 linhas
13 KiB

  1. $Id: README,v 1.4 2005/12/08 12:05:06 chandrusf Exp $
  2. ibrowse is a HTTP client. The following are a list of features.
  3. - RFC2616 compliant (AFAIK)
  4. - supports GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE only
  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. - Named 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. Comments to : Chandrashekhar.Mullaparthi@t-mobile.co.uk
  17. CONTRIBUTIONS & CHANGE HISTORY
  18. ==============================
  19. 08-May-2005 - Youns Hafri made a CRUX LINUX port of ibrowse.
  20. http://yhafri.club.fr/crux/index.html
  21. 22-Nov-2005 - Added ability to generate requests using the Chunked
  22. Transfer-Encoding.
  23. 08-Dec-2005 - Richard Cameron (camster@citeulike.org). Patch to ibrowse to
  24. prevent port number being included in the Host header when port
  25. 80 is intended.
  26. Here are some usage examples. Enjoy!
  27. 5> ibrowse:start().
  28. {ok,<0.94.0>}
  29. %% A simple GET
  30. 6> ibrowse:send_req("http://intranet/messenger/", [], get).
  31. {ok,"200",
  32. [{"Server","Microsoft-IIS/5.0"},
  33. {"Content-Location","http://intranet/messenger/index.html"},
  34. {"Date","Fri, 17 Dec 2004 15:16:19 GMT"},
  35. {"Content-Type","text/html"},
  36. {"Accept-Ranges","bytes"},
  37. {"Last-Modified","Fri, 17 Dec 2004 08:38:21 GMT"},
  38. {"Etag","\"aa7c9dc313e4c41:d77\""},
  39. {"Content-Length","953"}],
  40. "<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>"}
  41. %% =============================================================================
  42. %% A GET using a proxy
  43. 7> ibrowse:send_req("http://www.google.com/", [], get, [],
  44. [{proxy_user, "XXXXX"},
  45. {proxy_password, "XXXXX"},
  46. {proxy_host, "proxy"},
  47. {proxy_port, 8080}], 1000).
  48. {ok,"302",
  49. [{"Date","Fri, 17 Dec 2004 15:22:56 GMT"},
  50. {"Content-Length","217"},
  51. {"Content-Type","text/html"},
  52. {"Set-Cookie",
  53. "PREF=ID=f58155c797f96096:CR=1:TM=1103296999:LM=1103296999:S=FiWdtAqQvhQ0TvHq; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"},
  54. {"Server","GWS/2.1"},
  55. {"Location",
  56. "http://www.google.co.uk/cxfer?c=PREF%3D:TM%3D1103296999:S%3Do8bEY2FIHwdyGenS&prev=/"},
  57. {"Via","1.1 netapp01 (NetCache NetApp/5.5R2)"}],
  58. "<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"}
  59. %% =============================================================================
  60. %% A GET response saved to file. A temporary file is created and the
  61. %% filename returned. The response will only be saved to file is the
  62. %% status code is in the 200 range. The directory to download to can
  63. %% be set using the application env var 'download_dir' - the default
  64. %% is the current working directory.
  65. 8> ibrowse:send_req("http://www.erlang.se/", [], get, [],
  66. [{proxy_user, "XXXXX"},
  67. {proxy_password, "XXXXX"},
  68. {proxy_host, "proxy"},
  69. {proxy_port, 8080},
  70. {save_response_to_file, true}], 1000).
  71. {error,req_timedout}
  72. %% =============================================================================
  73. 9> ibrowse:send_req("http://www.erlang.se/", [], get, [],
  74. [{proxy_user, "XXXXX"},
  75. {proxy_password, "XXXXX"},
  76. {proxy_host, "proxy"},
  77. {proxy_port, 8080},
  78. {save_response_to_file, true}], 5000).
  79. {ok,"200",
  80. [{"Transfer-Encoding","chunked"},
  81. {"Date","Fri, 17 Dec 2004 15:24:36 GMT"},
  82. {"Content-Type","text/html"},
  83. {"Server","Apache/1.3.9 (Unix)"},
  84. {"Via","1.1 netapp01 (NetCache NetApp/5.5R2)"}],
  85. {file,"/Users/chandru/code/ibrowse/src/ibrowse_tmp_file_1103297041125854"}}
  86. %% =============================================================================
  87. %% Setting size of connection pool and pipeline size. This sets the
  88. %% number of maximum connections to this server to 10 and the pipeline
  89. %% size to 1. Connections are setup a required.
  90. 11> ibrowse:set_dest("www.hotmail.com", 80, [{max_sessions, 10},
  91. {max_pipeline_size, 1}]).
  92. ok
  93. %% =============================================================================
  94. %% Example using the HEAD method
  95. 56> ibrowse:send_req("http://www.erlang.org", [], head).
  96. {ok,"200",
  97. [{"Date","Mon, 28 Feb 2005 04:40:53 GMT"},
  98. {"Server","Apache/1.3.9 (Unix)"},
  99. {"Last-Modified","Thu, 10 Feb 2005 09:31:23 GMT"},
  100. {"Etag","\"8d71d-1efa-420b29eb\""},
  101. {"Accept-ranges","bytes"},
  102. {"Content-Length","7930"},
  103. {"Content-Type","text/html"}],
  104. []}
  105. %% =============================================================================
  106. %% Example using the OPTIONS method
  107. 62> ibrowse:send_req("http://www.sun.com", [], options).
  108. {ok,"200",
  109. [{"Server","Sun Java System Web Server 6.1"},
  110. {"Date","Mon, 28 Feb 2005 04:44:39 GMT"},
  111. {"Content-Length","0"},
  112. {"P3p",
  113. "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\""},
  114. {"Set-Cookie",
  115. "SUN_ID=X.X.X.X:169191109565879; EXPIRES=Wednesday, 31-Dec-2025 23:59:59 GMT; DOMAIN=.sun.com; PATH=/"},
  116. {"Allow",
  117. "HEAD, GET, PUT, POST, DELETE, TRACE, OPTIONS, MOVE, INDEX, MKDIR, RMDIR"}],
  118. []}
  119. %% =============================================================================
  120. %% Example of using Asynchronous requests
  121. 18> ibrowse:send_req("http://www.google.com", [], get, [],
  122. [{proxy_user, "XXXXX"},
  123. {proxy_password, "XXXXX"},
  124. {proxy_host, "proxy"},
  125. {proxy_port, 8080},
  126. {stream_to, self()}]).
  127. {ibrowse_req_id,{1115,327256,389608}}
  128. 19> flush().
  129. Shell got {ibrowse_async_headers,{1115,327256,389608},
  130. "302",
  131. [{"Date","Thu, 05 May 2005 21:06:41 GMT"},
  132. {"Content-Length","217"},
  133. {"Content-Type","text/html"},
  134. {"Set-Cookie",
  135. "PREF=ID=b601f16bfa32f071:CR=1:TM=1115327201:LM=1115327201:S=OX5hSB525AMjUUu7; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"},
  136. {"Server","GWS/2.1"},
  137. {"Location",
  138. "http://www.google.co.uk/cxfer?c=PREF%3D:TM%3D1115327201:S%3DDS9pDJ4IHcAuZ_AS&prev=/"},
  139. {"Via",
  140. "1.1 hatproxy01 (NetCache NetApp/5.6.2)"}]}
  141. Shell got {ibrowse_async_response,{1115,327256,389608},
  142. "<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"}
  143. Shell got {ibrowse_async_response_end,{1115,327256,389608}}
  144. ok
  145. %% =============================================================================
  146. %% Another example of using async requests
  147. 24> ibrowse:send_req("http://yaws.hyber.org/simple_ex2.yaws", [], get, [],
  148. [{proxy_user, "XXXXX"},
  149. {proxy_password, "XXXXX"},
  150. {proxy_host, "proxy"},
  151. {proxy_port, 8080},
  152. {stream_to, self()}]).
  153. {ibrowse_req_id,{1115,327430,512314}}
  154. 25> flush().
  155. Shell got {ibrowse_async_headers,{1115,327430,512314},
  156. "200",
  157. [{"Date","Thu, 05 May 2005 20:58:08 GMT"},
  158. {"Content-Length","64"},
  159. {"Content-Type","text/html;charset="},
  160. {"Server",
  161. "Yaws/1.54 Yet Another Web Server"},
  162. {"Via",
  163. "1.1 hatproxy01 (NetCache NetApp/5.6.2)"}]}
  164. Shell got {ibrowse_async_response,{1115,327430,512314},
  165. "<html>\n\n\n<h1> Yesssssss </h1>\n\n<h2> Hello again </h2>\n\n\n</html>\n"}
  166. Shell got {ibrowse_async_response_end,{1115,327430,512314}}
  167. %% =============================================================================
  168. %% Example of request which fails when using the async option. Here
  169. %% the {ibrowse_req_id, ReqId} is not returned. Instead the error code is
  170. %% returned.
  171. 68> ibrowse:send_req("http://www.earlyriser.org", [], get, [], [{stream_to, self()}]).
  172. {error,conn_failed}
  173. %% Example of request using both Proxy-Authorization and authorization by the final webserver.
  174. 17> ibrowse:send_req("http://www.erlang.se/lic_area/protected/patches/erl_756_otp_beam.README",
  175. [], get, [],
  176. [{proxy_user, "XXXXX"},
  177. {proxy_password, "XXXXX"},
  178. {proxy_host, "proxy"},
  179. {proxy_port, 8080},
  180. {basic_auth, {"XXXXX", "XXXXXX"}}]).
  181. {ok,"200",
  182. [{"Accept-Ranges","bytes"},
  183. {"Date","Thu, 05 May 2005 21:02:09 GMT"},
  184. {"Content-Length","2088"},
  185. {"Content-Type","text/plain"},
  186. {"Server","Apache/1.3.9 (Unix)"},
  187. {"Last-Modified","Tue, 03 May 2005 15:08:18 GMT"},
  188. {"ETag","\"1384c8-828-427793e2\""},
  189. {"Via","1.1 hatproxy01 (NetCache NetApp/5.6.2)"}],
  190. "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"}
  191. %% =============================================================================
  192. %% Example of a TRACE request. Very interesting! yaws.hyber.org didn't
  193. %% support this. Nor did www.google.com. But good old BBC supports
  194. %% this.
  195. 35> 37> ibrowse:send_req("http://www.bbc.co.uk/", [], trace, [],
  196. [{proxy_user, "XXXXX"},
  197. {proxy_password, "XXXXX"},
  198. {proxy_host, "proxy"},
  199. {proxy_port, 8080}]).
  200. {ok,"200",
  201. [{"Transfer-Encoding","chunked"},
  202. {"Date","Thu, 05 May 2005 21:40:27 GMT"},
  203. {"Content-Type","message/http"},
  204. {"Server","Apache/2.0.51 (Unix)"},
  205. {"Set-Cookie",
  206. "BBC-UID=7452e72a29424c5b0b232c7131c7d9395d209b7170e8604072e0fcb3630467300; expires=Mon, 04-May-09 21:40:27 GMT; path=/; domain=bbc.co.uk;"},
  207. {"Set-Cookie",
  208. "BBC-UID=7452e72a29424c5b0b232c7131c7d9395d209b7170e8604072e0fcb3630467300; expires=Mon, 04-May-09 21:40:27 GMT; path=/; domain=bbc.co.uk;"},
  209. {"Via","1.1 hatproxy01 (NetCache NetApp/5.6.2)"}],
  210. "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"}