<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>26253</bug_id>
          
          <creation_ts>2014-07-02 19:48:23 +0000</creation_ts>
          <short_desc>Why is the url attribute of the Request interface a ScalarValueString instead of an URL?</short_desc>
          <delta_ts>2014-07-07 23:50:11 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>Fetch</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tobie Langel">tobie.langel</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>d</cc>
    
    <cc>jaffathecake</cc>
    
    <cc>jungkees</cc>
    
    <cc>mike</cc>
          
          <qa_contact>sideshowbarker+fetchspec</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>108657</commentid>
    <comment_count>0</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-02 19:48:23 +0000</bug_when>
    <thetext></thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108658</commentid>
    <comment_count>1</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-02 19:50:55 +0000</bug_when>
    <thetext>Concerned we&apos;re going to see a lot of:

var requestURL = new URL(event.request.url);

e.g.: https://github.com/jakearchibald/trained-to-thrill/blob/3c6490361e1e373841de3ce8df82a195469be82f/www/static/js/sw.js#L20</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108661</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-02 20:46:04 +0000</bug_when>
    <thetext>Maybe. I don&apos;t want to return a mutable URL. Maybe something like http://url.spec.whatwg.org/#urlutilsreadonly Or we could offer a asURL() method that returns a new URL object each time.

  var requestURL = event.request.asURL()</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108665</commentid>
    <comment_count>3</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-02 22:38:37 +0000</bug_when>
    <thetext>(In reply to Anne from comment #2)
&gt; Maybe. I don&apos;t want to return a mutable URL. Maybe something like
&gt; http://url.spec.whatwg.org/#urlutilsreadonly

I like the readonly suggestion very much.

&gt; Or we could offer a asURL()
&gt; method that returns a new URL object each time.
&gt; 
&gt;   var requestURL = event.request.asURL()

This not so much; It&apos;s weird to have a url attribute which needs conversion.

On the other hand, URLUtilsReadOnly could have a clone (or toMutable) method that would return a mutable URL instance with the attributes set to the same value as the original one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108672</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 05:36:37 +0000</bug_when>
    <thetext>The asURL() suggestion was with the assumption we would keep url as returning a string.

The problem with #urlutilsreadonly is that it&apos;s a ton of attributes, including href.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108681</commentid>
    <comment_count>5</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 09:45:49 +0000</bug_when>
    <thetext>(In reply to Anne from comment #4)
&gt; The asURL() suggestion was with the assumption we would keep url as
&gt; returning a string.

Yes. Still. It&apos;s weird.

&gt; The problem with #urlutilsreadonly is that it&apos;s a ton of attributes,
&gt; including href.

What&apos;s wrong with that? (Genuine question.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108682</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 09:51:16 +0000</bug_when>
    <thetext>origin is a direct conflict. href duplicates url.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108684</commentid>
    <comment_count>7</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 10:12:21 +0000</bug_when>
    <thetext>You mean request.headers.get(&quot;origin&quot;) vs. request.url.origin?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108685</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 10:18:38 +0000</bug_when>
    <thetext>(In reply to Tobie Langel from comment #7)
&gt; You mean request.headers.get(&quot;origin&quot;) vs. request.url.origin?

I meant request.origin vs request.origin (if we implemented URLUtilsReadOnly on Request).

Changing request.url into returning an object of sorts would not match any existing pattern we have for URLs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108686</commentid>
    <comment_count>9</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 10:46:23 +0000</bug_when>
    <thetext>(In reply to Anne from comment #8) 
&gt; Changing request.url into returning an object of sorts would not match any
&gt; existing pattern we have for URLs.

I&apos;m not sure I understand what that means.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108687</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 10:52:28 +0000</bug_when>
    <thetext>What we have today is HTMLAnchorElement, HTMLAreaElement, and Location that all implement some variant of URLUtils. We don&apos;t have an object that has a property that returns an object that implements some variant of URLUtils.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108688</commentid>
    <comment_count>11</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 11:17:42 +0000</bug_when>
    <thetext>Well, that&apos;s one way of looking at it. I see the location object as a property of the window object, so request.url being an immutable instance of URL really doesn&apos;t surprise me. (I find it consistant, actually.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108689</commentid>
    <comment_count>12</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 11:21:03 +0000</bug_when>
    <thetext>Fair. I guess then there&apos;s the question as to whether this should be a class or a record as per https://github.com/w3c/screen-orientation/issues/13#issuecomment-47595155

I suspect class since this might become mutable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108690</commentid>
    <comment_count>13</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-07-03 12:20:03 +0000</bug_when>
    <thetext>I&apos;d like to push back a bit against the OP. I really liked the

var requestURL = new URL(event.request.url);

pattern when I saw it. It is a good way of having the platform expose (and accept) URLs in a uniform way, as ScalarValueStrings. That makes them easy to work with in various contexts where strings are simpler to work with. And it emphasizes to authors that you can manually construct a URL from any string at any time, when you want to get something mutable and decomposed. But that URL will be separate from the original one; it will be created specifically by you, for you.

Indeed, even if we create an immutable URL, people are still going to have to do

var requestURL = new MutableURL(event.request.url);

in order to get a mutable copy, for the cases where that&apos;s what they want.

This is already how things are done in Node, as one data point, although they call it `url.parse` instead of `new URL`.

---

All that said, if there is strong consensus that you need to design immutable versions of URL, URLSearchParams, etc., then I agree they would be classes, not records. Not because they are likely to become mutable in the future (wouldn&apos;t that defeat the entire point?) but because they are likely to have lots of shared behavior (like URLSearchParams&apos;s methods which access an internal multimap) in addition to simply storing data.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108694</commentid>
    <comment_count>14</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 13:46:37 +0000</bug_when>
    <thetext>&gt; Indeed, even if we create an immutable URL, people are still going to have to do
&gt; 
&gt; var requestURL = new MutableURL(event.request.url);

You could also add a clone method:

var requestURL = event.request.url.clone();

But that&apos;s a red herring if your plan is to drive people to use strings for URLs as much as possible. In which case, I agree, event.request.url should be a string. I also think new URL(str); instead of URL.parse(str); sends the wrong signal.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108695</commentid>
    <comment_count>15</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 13:52:09 +0000</bug_when>
    <thetext>(In reply to Tobie Langel from comment #14)
&gt; I also think new URL(str); instead of URL.parse(str); sends the
&gt; wrong signal.

If this is the only thing standing from this bug -&gt; WONTFIX. I&apos;ve asked numerous times for feedback on the URL Standard. Nobody ever came with the argument that new URL(input, base) sends the wrong signal.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108696</commentid>
    <comment_count>16</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 14:15:08 +0000</bug_when>
    <thetext>(In reply to Anne from comment #15)
&gt; If this is the only thing standing from this bug -&gt; WONTFIX. I&apos;ve asked
&gt; numerous times for feedback on the URL Standard. Nobody ever came with the
&gt; argument that new URL(input, base) sends the wrong signal.

Agreed. I had incorrectly assumed the goal of having new URL() was to push devs to use URL objects instead of strings as much as possible. Turns out it&apos;s exactly the opposite. In which case, we should close this as WONTFIX and I&apos;ll open a bug against the URL standard for favoring URL.parse instead of new URL().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108697</commentid>
    <comment_count>17</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-03 14:19:50 +0000</bug_when>
    <thetext>I don&apos;t see why we&apos;d ever add URL.parse given new URL is a thing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108698</commentid>
    <comment_count>18</comment_count>
    <who name="Tobie Langel">tobie.langel</who>
    <bug_when>2014-07-03 14:33:45 +0000</bug_when>
    <thetext>(In reply to Anne from comment #17)
&gt; I don&apos;t see why we&apos;d ever add URL.parse given new URL is a thing.

Well, I think we have to decide whether we want devs to use URL objects to represent URLs or use Strings instead.

If we want URLs to be mostly expressed as Strings, then we want a URL api that consists mostly of static functions (e.g. similar to what exists for JSON).

Otherwise, if we want mostly objects, then request.url should return one too.

Overall, I&apos;m concerned that we&apos;re creating a similar situation as we have between the String constructor and string primitives. But maybe, this just shows a misunderstanding on my part.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108775</commentid>
    <comment_count>19</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-07-07 23:50:11 +0000</bug_when>
    <thetext>(In reply to Tobie Langel from comment #18)

&gt; If we want URLs to be mostly expressed as Strings, then we want a URL api
&gt; that consists mostly of static functions (e.g. similar to what exists for
&gt; JSON).
&gt; 
&gt; ...
&gt; 
&gt; Overall, I&apos;m concerned that we&apos;re creating a similar situation as we have
&gt; between the String constructor and string primitives. But maybe, this just
&gt; shows a misunderstanding on my part.

I don&apos;t really see this as accurate. Having a structured class representing a mutable URL, versus representing a URL as a string, is a very different situation from having a useless immutable wrapper object (String objects), or stringifying/parsing arbitrary object/array/primitive graphs.

URL instances must come from somewhere. In theory they could have a constructor that is e.g. `new URL({ protocol, username, password, host, ... })`, or just `new URL()` (and then you individually set its components). And then `URL.parse` could generate an instance from a string. But in terms of ergonomic API design, I don&apos;t see that as a win. It doesn&apos;t seem to communicate anything different about how they are supposed to be used, certainly.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>