url-routing - Rebol 3 方案中的用户/密码

标签 url-routing rebol rebol3

在下面的端口规范中,我试图解析一个 URL 以确定用户、密码、主机和路径。用户/密码值是可选的,但如果不存在,我想为每个设置默认值。

然而,如果 user/pass 不存在,user/pass 会从 port/spec 对象中省略——这是为什么呢?

>> read sch://foo/bar.r
PORT/SPEC is an object of value: 
   title           string!   "Wee Scheme" 
   scheme          word!     sch 
   ref             url!      sch://foo/bar.r 
   path            string!   "/bar.r" 
   host            string!   "foo" 

>> read sch://foo:bar@foo/bar.r
PORT/SPEC is an object of value: 
   title           string!   "Wee Scheme" 
   scheme          word!     sch 
   ref             url!      sch://foo:bar@foo/bar.r 
   path            string!   "/bar.r" 
   pass            string!   "bar" 
   user            string!   "foo" 
   host            string!   "foo"

另外,在做这个题时,我在scheme中犯了一个错误,将解析规则绑定(bind)到port,而不是port/spec——值如何然后在port/spec对象中设置?

规范:

sys/make-scheme [
    name: 'sch
    title: "Wee Scheme"
    actor: [
        read: func [port][
            parse port/spec/ref use [chars][
                chars: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "-_!+%.,"]

                bind [
                    "sch://" [
                        copy user some chars #":"
                        copy pass some chars #"@"
                        | (user: 'mince pass: 'tatties)
                    ]
                    copy host some chars
                    copy path [some [#"/" any chars]]
                    end
                ] port
            ]
            ? port/spec
        ]
    ]
]

最佳答案

制定计划https://github.com/rebol/r3/blob/master/src/mezz/sys-ports.r#L254用作默认规范系统/标准/端口规范网络,它没有用户并通过。

>> system/standard/port-spec-net
== make object! [
    title: none
    scheme: none
    ref: none
    path: none
    host: none
    port-id: 80
]

因此,如果您想要用户并在规范中未通过时也通过,则必须像这样创建自己的规范 https://github.com/rebol/r3/blob/master/src/mezz/prot-http.r#L417并将它们放在那里。

关于url-routing - Rebol 3 方案中的用户/密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15445046/

相关文章:

scope - 如何在 Rebol 3 View 中设置变量并在窗口关闭后使用该值?

dll - 如何使用 LibFFI 支持构建 Rebol 的 "Ren-C"分支?

javascript - Spine.js 和 jquerymobile-router

rebol - 为什么 Rebol 列表中 'clear' 和 'unset' 的用法存在差异?

javascript - bolt 中的内容类型

memory-management - 为什么要在 rebol 中分配一个变量?

rebol - 指向同一个 Rebol 列表的 2 个变量怎么会有不同的指针呢?

javascript - 如何向实际的 post 请求添加额外的 req.body 属性,然后以 Express 方式重定向它

asp.net-web-api - ExtensionlessUrlHandler 和 "Recursion too deep; the stack overflowed"