在下面的端口规范中,我试图解析URL以确定用户,传递,主机和路径.用户/通过值是可选的,但我想为每个值设置默认值(如果不存在). 但是如果没有user / pass,则port / spec对象中省略了user / pa
但是如果没有user / pass,则port / spec对象中省略了user / pass – 这是为什么?
>> 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"
另外,在起草这个问题时,我在方案中犯了一个错误,并将解析规则绑定到端口,而不是port / spec-how然后如何在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 ] ] ]make-scheme https://github.com/rebol/r3/blob/master/src/mezz/sys-ports.r#L254使用默认的spec system / standard / port-spec-net,它没有用户和pass.
>> 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并将其设置在那里.