Skip to content

Instantly share code, notes, and snippets.

@pfrazee
Last active January 3, 2016 08:59
Show Gist options
  • Save pfrazee/8439653 to your computer and use it in GitHub Desktop.
Save pfrazee/8439653 to your computer and use it in GitHub Desktop.
Pro opinions plz

Background: The host page proxy

From inside a worker server, the only external hostname is "httpl://host.page"

To reach anything, the worker proxies through the hostpage.

"httpl://host.page/http%3A%2F%2Fexplorer%2F"

(This is why I want the percent-encoding rendering more nicely, but that's another topic.)

Background: The link header's extracted data

When links come back in the Link header, Local.js adds some extracted data.

From
Link: <http://foobar.com/foo>; rel="service"; title="foo"

to
Link: <http://foobar.com/foo>; host_domain="foobar.com"; rel="service"; title="foo"

If it's a global URI ([email protected]!foo.com!123) it also extracts and adds host_user, host_network, host_app, and host_sid. These are the host_* attrs.

They are helpful for navigating the links

agent.follow({ rel: 'gwr.io/chat', host_user: 'pfraze' }) // go to pfraze's chat

But it needs to be extracted from the URI so that the host_* attrs can always be trusted. Otherwise, rando server could do:

Link: <http://foo.com>; host_domain="lies.com"; title="This is totally lies.com not foo.com"

Problem: the proxy fucks up the link header's extracted data

This is how the response from a proxy gets transformed:

From
Link: <httpl://host.page/http%3A%2F%2Fexplorer%2F>; rel="service"; title="Explorer"

to
Link: <httpl://host.page/http%3A%2F%2Fexplorer%2F>; host_domain="host.page"; rel="service"; title="Explorer"

Oh noes, host_domain will always be "host.page". Not very useful that way -- I need to reason about the endpoint, not the proxy.

Because Localjs overwrites all the host_ attributes, the proxy can't override the host_ values.

Proposal 1: have the proxy add "upstream" attrs

From
Link: <httpl://host.page/http%3A%2F%2Fexplorer%2F>; rel="service"; title="Explorer"

to
Link: <httpl://host.page/http%3A%2F%2Fexplorer%2F>; host_domain="host.page"; up1_domain="explorer"; rel="service"; title="Explorer"

Above, that would be up1_domain. It's numbered to account for the possibility of multiple proxies.

Proposal 2: give the proxy special powers

Let the host page proxy override the host_ attributes. This can only work if the proxy is known to be trusted.

Proposal 3: add proxy awareness to Localjs

This means that all proxy URIs need to follow a format that local can predict and pick apart.

Proposal 4: dont let proxies alter the link headers

Instead, preserve the responses and let the client construct proxied URIs using the Via header

Via: HTTPL/0.1 host.page
Link: <httpl://explorer/>; rel="self service", </foo>; rel="item"; id="foo" 

becomes

Link: <httpl://host.page/httpl://explorer/>; host_domain="explorer"; rel="self service", <httpl://host.page/httpl://explorer/foo>; host_domain="explorer"; rel="item"; id="foo" 

Cons:

  • Can't distinguish between links which should or should not be proxied
  • Enforces only one kind of proxy URI (where the path is the subsequent request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment