~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/xmlrpc/httpserver.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# Implements a simple HTTP-server by using John W. Small's (jsmall@laser.net) 
 
2
# Implements a simple HTTP-server by using John W. Small's (jsmall@laser.net)
3
3
# ruby-generic-server.
4
 
 
4
#
5
5
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
6
6
#
7
 
# $Id: httpserver.rb 19657 2008-10-01 13:46:53Z mame $
 
7
# $Id: httpserver.rb 25189 2009-10-02 12:04:37Z akr $
8
8
#
9
9
 
10
10
 
14
14
 
15
15
  ##
16
16
  # handle_obj specifies the object, that receives calls to request_handler
17
 
  # and ip_auth_handler 
18
 
  def initialize(handle_obj, port = 8080, host = DEFAULT_HOST, maxConnections = 4, 
 
17
  # and ip_auth_handler
 
18
  def initialize(handle_obj, port = 8080, host = DEFAULT_HOST, maxConnections = 4,
19
19
                 stdlog = $stdout, audit = true, debug = true)
20
20
    @handler = handle_obj
21
21
    super(port, host, maxConnections, stdlog, audit, debug)
24
24
private
25
25
 
26
26
  # Constants -----------------------------------------------
27
 
  
 
27
 
28
28
  CRLF        = "\r\n"
29
29
  HTTP_PROTO  = "HTTP/1.0"
30
30
  SERVER_NAME = "HttpServer (Ruby #{RUBY_VERSION})"
46
46
  }
47
47
 
48
48
  # Classes -------------------------------------------------
49
 
  
 
49
 
50
50
  class Request
51
51
    attr_reader :data, :header, :method, :path, :proto
52
 
    
 
52
 
53
53
    def initialize(data, method=nil, path=nil, proto=nil)
54
54
      @header, @data = Table.new, data
55
55
      @method, @path, @proto = method, path, proto
56
56
    end
57
 
    
 
57
 
58
58
    def content_length
59
59
      len = @header['Content-Length']
60
60
      return nil if len.nil?
61
 
      return len.to_i 
 
61
      return len.to_i
62
62
    end
63
 
    
 
63
 
64
64
  end
65
 
  
 
65
 
66
66
  class Response
67
67
    attr_reader   :header
68
68
    attr_accessor :body, :status, :status_message
69
 
    
 
69
 
70
70
    def initialize(status=200)
71
71
      @status = status
72
72
      @status_message = nil
82
82
    include Enumerable
83
83
 
84
84
    def initialize(hash={})
85
 
      @hash = hash 
 
85
      @hash = hash
86
86
      update(hash)
87
87
    end
88
88
 
113
113
 
114
114
  def http_header(header=nil)
115
115
    new_header = Table.new(DEFAULT_HEADER)
116
 
    new_header.update(header) unless header.nil? 
 
116
    new_header.update(header) unless header.nil?
117
117
 
118
118
    new_header["Connection"] = "close"
119
119
    new_header["Date"]       = http_date(Time.now)
127
127
 
128
128
  def http_resp(status_code, status_message=nil, header=nil, body=nil)
129
129
    status_message ||= StatusCodeMapping[status_code]
130
 
    
 
130
 
131
131
    str = ""
132
132
    str << "#{HTTP_PROTO} #{status_code} #{status_message}" << CRLF
133
133
    http_header(header).writeTo(str)
137
137
  end
138
138
 
139
139
  # Main Serve Loop -----------------------------------------
140
 
  
141
 
  def serve(io)  
 
140
 
 
141
  def serve(io)
142
142
    # perform IP authentification
143
143
    unless @handler.ip_auth_handler(io)
144
144
      io << http_resp(403, "Forbidden")
149
149
    if io.gets =~ /^(\S+)\s+(\S+)\s+(\S+)/
150
150
      request = Request.new(io, $1, $2, $3)
151
151
    else
152
 
      io << http_resp(400, "Bad Request") 
 
152
      io << http_resp(400, "Bad Request")
153
153
      return
154
154
    end
155
 
     
 
155
 
156
156
    # parse HTTP headers
157
157
    while (line=io.gets) !~ /^(\n|\r)/
158
158
      if line =~ /^([\w-]+):\s*(.*)$/
160
160
      end
161
161
    end
162
162
 
163
 
    io.binmode    
 
163
    io.binmode
164
164
    response = Response.new
165
165
 
166
166
    # execute request handler
167
167
    @handler.request_handler(request, response)
168
 
   
 
168
 
169
169
    # write response back to the client
170
170
    io << http_resp(response.status, response.status_message,
171
 
                    response.header, response.body) 
 
171
                    response.header, response.body)
172
172
 
173
173
  rescue Exception => e
174
174
    io << http_resp(500, "Internal Server Error")