Index: [Article Count Order] [Thread]

Date: Thu, 23 May 2002 12:12:18 +0200
From: Lars Christensen <larsch@cs.auc.dk>
Subject: [webricken:98] Re: Full Request URL?
To: webricken@notwork.org
Message-Id: <20020523101218.GA22193@peta.cs.auc.dk>
In-Reply-To: <200205221134.g4MBYlrF065627@miso.k.notwork.org>
References: <20020522104939.GA27266@peta.cs.auc.dk> <200205221134.g4MBYlrF065627@miso.k.notwork.org>
X-Mail-Count: 00098

On Wed, May 22, 2002 at 08:34:47PM +0900, GOTO Kentaro wrote:> At Wed, 22 May 2002 12:49:39 +0200,> Lars Christensen wrote:> > > Is there a way to get the full URL of the requested document / resource=? My> > server has multiple domain names, and i'd like the full URL with the ho=stname> > that the client requested the resource on.> > HOST request header includes that information in HTTP/1.1. > Try access to http://your.domain:2002/foo/bar?baz=quux> >   require 'webrick'> >   s = WEBrick::HTTPServer.new(:Port => 2002)>   s.mount_proc("/"){|req, res|>     res.body = "http://#{req['host']}#{req.request_uri}";>   }>   s.startThanks. This helped in the case of HTTP/1.1. However, in the case of HTTP/1=.0(or others) it could be useful to have access to the return value ofSocket#addr of the local.  This following patch adds this to the httprequestclass.--- /user/larsch/src/ruby/webrick-1.1.5/lib/webrick/httprequest.rb      Wed= Feb 13 21:02:51 2002+++ httprequest.rb      Thu May 23 12:01:17 2002@@ -27,6 +27,7 @@     attr_reader :query     attr_reader :config     attr_reader :peeraddr+    attr_reader :localaddr     attr_accessor :script_name, :path_info      def initialize(config)@@ -70,6 +71,7 @@       end       @header['cookie'].each{ |cookie| @cookies += Cookie::parse(cookie)= }       @peeraddr = socket.respond_to?(:peeraddr) ? socket.peeraddr : []+      @localaddr = socket.respond_to?(:addr) ? socket.addr : []        if /close/io =~ self["connection"]         @keep_alive = falseThen you could do this:   url =   if host = req['host']     "http://#{host}";   else     "http://#{req.localaddr[2]}:#{req.localaddr[1]}";   end + req.request_urior similar.-- Lars Christensen
attatchment (application/pgp-signature) ignored