[#14715] HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...>

高橋征義です。

32 messages 1999/06/01
[#14834] Re: HTTP Client with Ruby — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/06/05

なひです.

[#14836] Re: HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...> 1999/06/05

高橋征義です。

[#14858] Re: HTTP Client with Ruby — gotoken@... (GOTO Kentaro) 1999/06/07

ごとけんです

[#14896] Re: HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...> 1999/06/07

高橋です。みなさまどうもありがとうございます。

[#14907] Re: HTTP Client with Ruby — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/06/08

なひです.

[#14766] ruby 1.3.4 on BSD/OS 3.1 — Yasunari Momoi <momo@...>

BSD/OS 3.1 (with kame) で ruby-1.3.4 を作ろうとしているんで

18 messages 1999/06/03
[#14770] Re: ruby 1.3.4 on BSD/OS 3.1 — matz@... (Yukihiro Matsumoto) 1999/06/03

まつもと ゆきひろです

[#15012] ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...>

22 messages 1999/06/16
[#15013] Re: ext ML の過去ログはいずこ? — Shin-ichiro Hara <sinara@...> 1999/06/16

原です。

[#15014] Re: ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...> 1999/06/16

[#15015] Re: ext ML の過去ログはいずこ? — Kazunori Akaishi <akaishi@...> 1999/06/16

akaishi です。

[#15016] Re: ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...> 1999/06/16

[#15045] mail library — Minero Aoki <aamine@...>

あおきです。

96 messages 1999/06/20
[#15075] Re: mail library — Minero Aoki <aamine@...> 1999/06/22

あおきです。

[#15122] Re: mail library — Minero Aoki <aamine@...> 1999/06/28

あおきです。

[#15123] Re: mail library — matz@... (Yukihiro Matsumoto) 1999/06/28

まつもと ゆきひろです

[#15125] Re: mail library — WATANABE Hirofumi <watanabe@...> 1999/06/28

わたなべです.

[#15126] Re: mail library — matz@... (Yukihiro Matsumoto) 1999/06/28

まつもと ゆきひろです

[#15146] Re: mail library — Minero Aoki <aamine@...> 1999/06/29

あおきです。

[#15148] Re: mail library — matz@... (Yukihiro Matsumoto) 1999/06/29

まつもと ゆきひろです

[#15161] Re: mail library — Minero Aoki <aamine@...> 1999/06/30

あおきです。

[#15165] Re: mail library — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/06/30

なひです.

[#15167] Re: mail library — Minero Aoki <aamine@...> 1999/06/30

あおきです。

[#15219] Re: mail library — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/03

なひです.

[#15228] Re: mail library — hisanori@... 1999/07/05

松尾です。

[#15279] Re: mail library — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/07

なひです.

[#15172] Re:mail library — Takeo Iwama <iwamat@...> 1999/07/01

はじめまして、岩間です。

[#15218] JUS workshop ( was Re:mail library ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/03

なひです.mod_rubyと格闘中です.

[#15220] Mod_ruby server does not respond when POST request. — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/03

なひです.mod_rubyネタはruby-listでよいでしょうか?

[#15226] Re: Mod_ruby server does not respond when POST request. — Shugo Maeda <shugo@...> 1999/07/05

前田です。

[#15240] mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 ( was Re: Mod_ruby server does not respond when POST request. ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/05

なひです.

[#15242] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 ( was Re: Mod_ruby server does not respond when POST request. ) — Shugo Maeda <shugo@...> 1999/07/05

前田です。

[#15308] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 — Katsuyuki Komatsu <komatsu@...> 1999/07/08

小松です。

[#15310] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 — Shugo Maeda <shugo@...> 1999/07/08

前田です。

[#15313] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 — Katsuyuki Komatsu <komatsu@...> 1999/07/08

小松です。

[#15057] 複雑?な構造体の定義方法 — Koichi Shigematsu <shige@...>

しげまつ と申します。  とっても久しぶりの投稿です。

18 messages 1999/06/21
[#15058] Re: 複雑?な構造体の定義方法 — matz@... (Yukihiro Matsumoto) 1999/06/21

まつもと ゆきひろです

[#15059] Re: 複雑?な構造体の定義方法 — Koichi Shigematsu <shige@...> 1999/06/21

しげまつ です。

[#15061] Re: 複雑?な構造体の定義方法 — matz@... (Yukihiro Matsumoto) 1999/06/21

まつもと ゆきひろです

[#15065] pattern (Re: 複雑?な構造体の定義方法) — gotoken@... (GOTO Kentaro) 1999/06/21

ごとけんです

[#15076] Re: pattern (Re: 複雑?な構造体の定義方法) — matz@... (Yukihiro Matsumoto) 1999/06/22

まつもと ゆきひろです

[#15077] Re: pattern (Re: 複雑?な構造体の定義方法) — gotoken@... (GOTO Kentaro) 1999/06/22

ごとけんです

[ruby-list:14950] Re: HTTP Client with Ruby

From: "NAKAMURA, Hiroshi" <nakahiro@...>
Date: 1999-06-09 04:42:19 UTC
List: ruby-list #14950
なひです.

http-access-0.0.1(originalバージョン)へのpatchです.

- ポート番号付きURL対応
- HTTP/1.0対応
- HTTPヘッダ区切りがLFのみであるサーバ対応(余計なお世話

の,つもりです.混乱させたみなさん,どうもすいません.

Persistent Connections対応強化ということで,
うっかりcloseし忘れるとソケットハンドルリークを起こすので,
ご利用の場合は注意してくださいね.^^;

	/	/	/

diff -ur http-access-0.0.1.dist/http-access.rb http-access-0.0.1/http-access.rb
--- http-access-0.0.1.dist/http-access.rb	Wed Mar  3 16:23:02 1999
+++ http-access-0.0.1/http-access.rb	Wed Jun  9 13:37:18 1999
@@ -29,7 +29,7 @@
 
   def initialize(host, port=HTTP_Port, proxy=nil)
     @host = host
-    @port = port
+    @port = port || HTTP_Port
     @state = :INIT
     @requests = []
     @uagent = format("HTTPAccess/0.0.1 (%s; %s)",
@@ -54,8 +54,8 @@
     header = {} unless header.kind_of? Hash
     header['Host'] = @host unless header['Host']
     header['User-Agent'] = @uagent unless header['User-Agent']
-    #header['Connection'] = 'Keep-Alive' unless header['Connection']
-    #header['Accept'] = '*/*' unless header['Accept']
+    header['Connection'] = 'Keep-Alive' unless header['Connection']
+    header['Accept'] = '*/*' unless header['Accept']
     header.each {|k, v|
       @socket.putheader(k, v)
     }
@@ -84,7 +84,7 @@
 
   # close the connection
   def close
-    @socket.close
+    @socket.close unless @socket.closed?
     @state = :INIT
   end
 
@@ -97,8 +97,8 @@
 
     req = @requests.shift
 
-    @status_line = @socket.gets("\r\n")
-    unless /(HTTP\/1\.\d+)\s+(\d\d\d)\s+(.*)/ =~ @status_line
+    @status_line = @socket.gets
+    unless /^(HTTP\/1\.\d+)\s+(\d\d\d)\s+(.*)\r?$/ =~ @status_line
       raise HTTPBadResponse
     end
     @http_version = $1
@@ -107,7 +107,7 @@
     @next_connection = true if @http_version == 'HTTP/1.1'
 
     @headers = []
-    until (line = @socket.gets("\r\n")) == "\r\n"
+    until (line = @socket.gets) =~ /^\r?$/
       if line == /^\s/
 	@headers[-1] << line
       else
@@ -117,6 +117,7 @@
 
     @content_length = nil
     @chunked = false
+    @next_connection = false
     @headers.each {|line|
       case line
       when /^Content-Length:\s+(\d+)/i
@@ -139,6 +140,11 @@
     @state = :DATA
     if req[0] == 'HEAD'
       @content_length = 0
+      if @next_connection
+      	@state = :WAIT
+      else
+     	close
+      end
     end
 
     @next_connection = false unless @content_length
@@ -148,7 +154,9 @@
 
   def get_header(&block)
     get_response if @state == :META
-    raise HTTPInvalidState, 'state != DATA' unless @state == :DATA
+    # @state might be :INIT now
+    #	because the session could be closed in get_response when HTTP/1.0.
+    #raise HTTPInvalidState, 'state != DATA' unless @state == :DATA
     if block
       @headers.each {|line|
 	block.call(line)
@@ -171,14 +179,25 @@
 
   def get_data(maxbytes=nil, &block)
     get_response if @state == :META
+    return nil if eof?
     raise HTTPInvalidState, 'state != DATA' unless @state == :DATA
+    data = nil
     if block
       until eof?
 	block.call(read_body(maxbytes))
       end
+      data = nil	# calling with block returns nil.
     else
-      read_body(maxbytes)
+      data = read_body(maxbytes)
+    end
+    if eof?
+      if @next_connection
+      	@state = :WAIT
+      else
+      	close
+      end
     end
+    data
   end
 
   def read_body(maxbytes=nil)
@@ -254,11 +273,31 @@
   url = URL.new(urlstr)
   #exit
 
-  h = HTTPAccess.new(url.netloc)
+  h = HTTPAccess.new(url.host, url.port)
+  #
+  p "get_header with block"
   h.request_head(url.path)
-  h.request_get(url.path, 'User-Agent'=>'FooBar/1.0')
   h.get_response
   h.get_header {|line| p line}
+  #
+  p "get_header without block"
+  h.request_head(url.path)
   h.get_response
+  p h.get_header
+  #
+  p "get_data with block"
+  h.request_get(url.path, 'User-Agent'=>'FooBar/1.0')
+  h.get_response
+  h.get_header {|line| p line}
   h.get_data(8192) {|data| p data}
+  #
+  p "get_data without block"
+  h.request_get(url.path, 'User-Agent'=>'FooBar/1.0')
+  h.get_response
+  h.get_header {|line| p line}
+  str = ""
+  while ( str = h.get_data( 1024 ))
+    p str
+  end
+  h.close
 end
diff -ur http-access-0.0.1.dist/url-parse.rb http-access-0.0.1/url-parse.rb
--- http-access-0.0.1.dist/url-parse.rb	Wed Mar  3 16:20:08 1999
+++ http-access-0.0.1/url-parse.rb	Tue Jun  8 10:17:41 1999
@@ -1,6 +1,6 @@
 # Parse URLs.
 class URL
-  attr_reader :urlstr, :scheme, :netloc, :path, :params, :query, :fragment
+  attr_reader :urlstr, :scheme, :netloc, :host, :port, :path, :params, :query, :fragment
 
   Uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet', 'wais',
     'https', 'shttp', 'snews', 'prospero', '']
@@ -14,15 +14,20 @@
   # [scheme]://[netloc]/[path];[params]?[query]#[fragment]
   def parse(url, scheme = nil, allow_fragments = true)
     @scheme = scheme
-    @netloc = @params = @query = @fragment = nil
+    @netloc = @host = @port = @params = @query = @fragment = nil
 
     if url =~ /^([-+\.\w]+):/
       @scheme, url = $1, $' #'
     end
 
     if url =~ /^(\/\/)?([^\/]+)/ && Uses_netloc.include?(@scheme)
-      # //[netloc]
+      # //[netloc] a.k.a. hostport ::= host [ : port ] in RFC1630
       @netloc, url = $2, $' #'
+      if @netloc =~ /^([^:]+):(\d*)$/	# Is this valid like 'http://foo:/bar'?
+      	@host, @port = $1, $2
+      else
+	@host = @netloc
+      end
     elsif url =~ /^(\/|~)/
       @scheme = 'file'
     else

In This Thread