Permalink
Browse files

Parametrize server methods

  • Loading branch information...
1 parent 110c4a0 commit 5aa5e282ab1062397cb6ff778e29a48f3876fb2e @VictorNicollet committed Oct 4, 2012
Showing with 15 additions and 14 deletions.
  1. +5 −5 src/action.ml
  2. +2 −2 src/action.mli
  3. +8 −7 src/action_Server.ml
View
@@ -26,7 +26,7 @@ let dispatch_define (server,prefix,args) action =
let value protocol domain port suffix cgi =
match Args.parse args suffix with None -> None | Some args ->
match server # matches protocol domain port with None -> None | Some s ->
- Some (server # cookie_domain, action (new fcgi_request endpt s args cgi))
+ Some (server # cookie_domain s, action (new fcgi_request endpt s args cgi))
in
Hashtbl.add defined key value
@@ -148,10 +148,10 @@ module Convenience = struct
let defport, protocol = if secure then 443,`HTTPS else 80,`HTTP in
let port = BatOption.default defport port in
(object
- method protocol = protocol
+ method protocol () = protocol
method domain () = domain
method port () = port
- method cookie_domain = cookies
+ method cookie_domain () = cookies
method matches pr dom po =
if po = port && pr = protocol && domain = dom then Some () else None
end)
@@ -161,10 +161,10 @@ module Convenience = struct
let port = BatOption.default defport port in
let cut = String.length suffix in
(object
- method protocol = protocol
+ method protocol _ = protocol
method domain s = s ^ suffix
method port _ = port
- method cookie_domain = cookies
+ method cookie_domain _ = cookies
method matches pr dom po =
if po = port && pr = protocol && BatString.ends_with dom suffix
then Some (BatString.left dom (String.length dom - cut)) else None
View
@@ -22,7 +22,7 @@
class type ['param] server = object
(** Is this server HTTP or HTTPS ? *)
- method protocol : [`HTTP|`HTTPS]
+ method protocol : 'param -> [`HTTP|`HTTPS]
(** What is the domain name for this server ? *)
method domain : 'param -> string
@@ -33,7 +33,7 @@ class type ['param] server = object
(** What is the cookie domain name for this server ? Cookies emitted by this server will be bound
to this domain, which may make them available to other servers based on the standard cookie
rules. Return [None] to set the cookie only for the current domain. *)
- method cookie_domain : string option
+ method cookie_domain : 'param -> string option
(** Does this server match an incoming request ? If so, extract the parameter that can be used to
generate another request on this domain. *)
View
@@ -7,17 +7,18 @@ module BS = BatString
open Action_Common
class type ['param] server = object
- method protocol : [`HTTP|`HTTPS]
- method domain : 'param -> string
- method port : 'param -> int
- method cookie_domain : string option
- method matches : [`HTTP|`HTTPS] -> string -> int -> 'param option
+ method protocol : 'param -> [`HTTP|`HTTPS]
+ method domain : 'param -> string
+ method port : 'param -> int
+ method cookie_domain : 'param -> string option
+ method matches : [`HTTP|`HTTPS] -> string -> int -> 'param option
end
let server_root server param =
+ let protocol = server # protocol param in
String.concat ""
- ( (match server # protocol with `HTTP -> "http://" | `HTTPS -> "https://")
+ ( (match protocol with `HTTP -> "http://" | `HTTPS -> "https://")
:: (server # domain param)
- :: (match server # protocol, server # port param with
+ :: (match protocol, server # port param with
| `HTTPS, 443 | `HTTP, 80 -> []
| _, port -> [ ":" ; string_of_int port ]))

0 comments on commit 5aa5e28

Please sign in to comment.