Location header must be an absolute URL:
*adapt file-dir-handler's 301 response *new procs GET-SOCKET-HOSTNAME-AND-PORTNUMBER, GET-SOCKET-HOST-STRING
This commit is contained in:
parent
96b485294f
commit
8974332da1
|
@ -252,10 +252,16 @@
|
|||
(send-file-response fname info req options))
|
||||
|
||||
((directory) ; Send back a redirection "foo" -> "foo/"
|
||||
(let* ((url (request-url req))
|
||||
(url-string (http-url->url-string url))
|
||||
(location-prefix
|
||||
(if (absolute-url? url)
|
||||
url-string
|
||||
(string-append
|
||||
"http://" (get-socket-host-string req) url-string))) ;we don't support virtual hosts yet!
|
||||
(location (string-append location-prefix "/")))
|
||||
(make-error-response
|
||||
(status-code moved-perm) req
|
||||
(string-append (http-url->url-string (request-url req))
|
||||
"/")))
|
||||
(status-code moved-perm) req location)))
|
||||
|
||||
(else (make-error-response (status-code forbidden) req)))))
|
||||
|
||||
|
|
|
@ -2,10 +2,28 @@
|
|||
|
||||
;;; This file is part of the Scheme Untergrund Networking package.
|
||||
|
||||
;;; Copyright (c) 2002 by Andreas Bernauer.
|
||||
;;; For copyright information, see the file COPYING which comes with
|
||||
;;; the distribution.
|
||||
|
||||
;;; interpolate hostname/IP address and portnumber from our request's net connection.
|
||||
;;; return host as string and portnumber as integer.
|
||||
(define (get-socket-hostname-and-portnumber req)
|
||||
(let ((addr (socket-local-address (request-socket req))))
|
||||
(with-fatal-error-handler
|
||||
(lambda (c more)
|
||||
(call-with-values (lambda ()(socket-address->internet-address addr))
|
||||
(lambda (ipaddr portnum) (values (format-internet-host-address ipaddr) portnum))))
|
||||
(values (host-info:name (host-info addr)) (service-info:port (service-info addr))))))
|
||||
|
||||
;; interpolate host info from our request's net connection.
|
||||
;; return string "foo.bar.org:7777" or "134.2.12.72:7777"
|
||||
(define (get-socket-host-string req)
|
||||
(call-with-values
|
||||
(lambda () (get-socket-hostname-and-portnumber req))
|
||||
(lambda (host portnum) (string-append host ":" (number->string portnum)))))
|
||||
|
||||
|
||||
;;; interpolate hostname or IP address from socket local address. return a string
|
||||
(define (host-name-or-ip addr)
|
||||
(with-fatal-error-handler
|
||||
(lambda (condition more)
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
http-url-path
|
||||
http-url-query
|
||||
|
||||
absolute-url?
|
||||
url-string->http-url
|
||||
http-url->url-string
|
||||
http-url-path->path-string))
|
||||
|
@ -237,7 +238,9 @@
|
|||
format-port))
|
||||
|
||||
(define-interface sunet-utilities-interface
|
||||
(export host-name-or-ip
|
||||
(export get-socket-hostname-and-portnumber
|
||||
get-socket-host-string
|
||||
host-name-or-ip
|
||||
on-interrupt
|
||||
socket-address->string
|
||||
dump
|
||||
|
|
Loading…
Reference in New Issue