network-uri icon indicating copy to clipboard operation
network-uri copied to clipboard

Why the : before the port in the URI record?

Open rrichardson opened this issue 10 years ago • 7 comments

I see that putting a : character in front of the port is clearly intentional : https://github.com/haskell/network-uri/blob/master/Network/URI.hs#L602

Two questions:

  1. Could this be a Maybe Int instead of a string? Most URI implementations store this as an integer and it is far more convenient. Failing that..
  2. Why is there a : in front of the value? This makes it rather annoying to parse out.

rrichardson avatar Aug 26 '14 22:08 rrichardson

  1. I'm afraid that would be a too breaking change at this point. I agree that it would have been better.

  2. I asked Graham Klyne, the original author of Network.URI, about this a while ago and he said that

    The inclusion of ":" in the scheme was, IIRC, to make recomposition of URIs and URI references from their components easier to do and more regular. I think there were some edge cases that became tricky to handle if the ":" was not part of the scheme.

The URI module is quite crufty and we're really in need a of a modern replacement (faster, different data types, etc). I'm just keeping network-uri on life-support in the mean time, so don't expect any drastic improvements in this package.

tibbe avatar Aug 27 '14 10:08 tibbe

I bumped my head on the same issue. If there's interest, @jonplussed and I are probably going to go off and make some minor type cleanups on a fork.

twopoint718 avatar Dec 08 '14 15:12 twopoint718

@twopoint718 see also #11

hvr avatar Dec 22 '14 09:12 hvr

@twopoint718 I'd be interested in what yourself and @jonplussed are intending on doing. Are you planning on using Text for URI processing, migrating away from String?

robstewart57 avatar Dec 22 '14 09:12 robstewart57

@robstewart57 I was wondering if the port number should be a PortNumber from the Network package: https://hackage.haskell.org/package/network-2.6.0.2/docs/Network.html#t:PortNumber ? It seems that reading this as an Int is weird. Why would someone want to add or subtract port numbers? My only idea was that very simple tweak.

twopoint718 avatar Dec 22 '14 16:12 twopoint718

@twopoint718 Note that PortNumber implements Num as well, so it doesn't solve that add/subtract problem.

lambda-fairy avatar Apr 07 '15 23:04 lambda-fairy

@lfairy ah, I didn't see that! My intent behind the proposal was mostly for the documentation effect of using PortNumber rather than Int.

twopoint718 avatar Apr 07 '15 23:04 twopoint718