Summary

add make-uri constructor to uri-generic and uri-common

Metadata

Attachments

Description

Currently the only constructors for uri-generic and uri-common URI records are uri-reference and absolute-uri. This is slightly inconvenient when constructing a URI from individual components. For example, when starting Spiffy one might want to construct the URI it can be reached by. Currently one has to do something like this:

 (update-uri (uri-reference "")
             scheme: (if (secure-connection?) 'https 'http)
             port: (server-port)
             host: (or (server-bind-address)
                       "0.0.0.0"))

Whereas this would be much nicer:

 (make-uri scheme: (if (secure-connection?) 'https 'http)
           port: (server-port)
           host: (or (server-bind-address)
                     "0.0.0.0"))
 

It also seems more complete to have make-uri in those eggs. Attached is a patch that implements it for both eggs in terms of update-uri so as to touch as little code as possible. Feel free to apply it or re-implement it the other way around :-)

Changes and comments

[2011-09-22 21:15:43 UTC] syn attached make-uri-for-uri-generic-and-uri-common.patch (description=#f)

[2011-09-23 04:56:14 UTC] iraikov wrote:

Thanks for the patch. The implementation of your make-uri seems ok, but there is an existing make-uri (actually make-URI) procedure, which is used internally. I would accept the patch if a different name was used. I suggest uri-from-parts but you are welcome to come up with a better suggestion.

[2011-09-23 14:36:35 UTC] syn wrote:

Indeed, but there is also an internal procedure update-URI, yet the module exports a different function as update-uri. I would prefer make-uri for consistency with other record types. It's up to you though!

[2011-10-03 13:44:13 UTC] iraikov wrote:

You are right, there is quite of bit of case mixup between internal and external procedures, so your patch would not make things worse. I have applied it to uri-generic and made a new release, 2.36.

Replying to syn: > Indeed, but there is also an internal procedure update-URI, yet the module exports a different function as update-uri. I would prefer make-uri for consistency with other record types. It's up to you though!

[2011-10-06 09:58:56 UTC] felix removed milestone 4.8.0

[2011-10-18 15:33:32 UTC] syn wrote:

Hi Ivan,

thanks for applying the patch! What about the one for uri-common though? Do you object to its application or did you just overlook it?

[2012-01-07 18:05:42 UTC] syn wrote:

I just ran into make-uri missing from uri-common again so I thought I'd check back on the issue :-)

[2012-01-08 14:08:26 UTC] sjamaan wrote:

Sorry about that, I had completely forgotten about it. I've added some tests to both uri-generic and uri-common for the constructor. This found a bug which I fixed (if you passed no path to the constructor, it failed). I've released uri-generic 2.37 and uri-common 1.3 so I'm closing this ticket.

If there's still something missing or wrong, please reopen the ticket or file a new one.

[2012-01-08 14:08:26 UTC] sjamaan changed status from new to closed

[2012-01-08 14:08:26 UTC] sjamaan set resolution to fixed