Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway: make IPNSHostname work on responses too #1577

Merged
merged 2 commits into from Aug 19, 2015
Merged

gateway: make IPNSHostname work on responses too #1577

merged 2 commits into from Aug 19, 2015

Conversation

ghost
Copy link

@ghost ghost commented Aug 14, 2015

IPNSHostnameOption() touches the URL path only on the way in,
but not on the way out. This commit makes it complete by
touching the following URLs in responses:

  • Heading, file links, back links in directory listings
  • Redirecting /foo to /foo/ if there's an index.html link
  • Omit Suborigin header

License: MIT
Signed-off-by: Lars Gierth larsg@systemli.org

@jbenet jbenet added the status/in-progress In progress label Aug 14, 2015
@jbenet
Copy link
Member

jbenet commented Aug 15, 2015

@lgierth i think i get it, but to be sure, can maybe describe a bit more in the code as a comment somewhere? or maybe want a test case that shows the cases it's supposed to be manipulating?

@ghost
Copy link
Author

ghost commented Aug 15, 2015

I clarified the comments.

maybe want a test case that shows the cases it's supposed to be manipulating?

Yes agreed, if we start serving our website using this, we better make sure it does what it says on the tin.

@jbenet
Copy link
Member

jbenet commented Aug 15, 2015

Yep. 👍


Sent from Mailbox

On Sat, Aug 15, 2015 at 3:17 PM, Lars Gierth notifications@github.com
wrote:

I clarified the comments.

maybe want a test case that shows the cases it's supposed to be manipulating?

Yes agreed, if we start serving our website using this, we better make sure it does what it says on the tin.

Reply to this email directly or view it on GitHub:
#1577 (comment)

t.Logf("k: %s\n", k)
ns["/ipns/example.net"] = path.FromString("/ipfs/" + k.String())

req, err := http.NewRequest("GET", ts.URL+"/ipfs/"+k.String(), nil)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The responds with 404...

@ghost
Copy link
Author

ghost commented Aug 16, 2015

There are a few unneccessary comments and a bit of duplication in there, I can clean that up, or we leave it for the great gateway bonfire (go-ipfs-gateway).

// we could use originalUrlPath like we do with the redirect,
// but i don't wanna break the switch-case right above, not now.
if urlPath != originalUrlPath {
backLink = "/" + strings.Join(pathSplit[4:], "/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that the only case where urlPath != originalUrlPath? because if not, we might panic the process (by accessing pathSplit[4:].

Maybe:

if urlPath != originalUrlPath && pathSplit[1] == "ipns" {
  backLink = "/" + strings.Join(pathSplit[4:], "/")
}

also, shouldn't it be pathSplit[3:] (3) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm piggybacking "path was touched by IPNSHostname" here, will change.

@jbenet
Copy link
Member

jbenet commented Aug 16, 2015

There are a few unneccessary comments and a bit of duplication in there, I can clean that up, or we leave it for the great gateway bonfire (go-ipfs-gateway).

yeah should be fine

@jbenet
Copy link
Member

jbenet commented Aug 16, 2015

@lgierth ok, CRed o/ -- a few comments

originalUrlPath := urlPath
hdr := r.Header["X-IPNS-Original-Path"]
if len(hdr) > 0 {
originalUrlPath = hdr[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe want to set here: ipnsHostRedirection = true and use that for the conditions below?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I introduced a variable in order to avoid the piggybacking. I also fixed backlink edge-cases and added more tests for them.

It should be good to go now.

@jbenet
Copy link
Member

jbenet commented Aug 17, 2015

@lgierth LGTM! one small comment above o/, and this:

  • if tests dont pass on all commits, squash the non-passing ones.

after that, Ready For Merge, i think

@daviddias daviddias mentioned this pull request Aug 17, 2015
28 tasks
Lars Gierth added 2 commits August 17, 2015 15:27
License: MIT
Signed-off-by: Lars Gierth <larsg@systemli.org>
IPNSHostnameOption() touches the URL path only on the way in,
but not on the way out. This commit makes it complete by
touching the following URLs in responses:

- Heading, file links, back links in directory listings
- Redirecting /foo to /foo/ if there's an index.html link
- Omit Suborigin header

License: MIT
Signed-off-by: Lars Gierth <larsg@systemli.org>
@ghost
Copy link
Author

ghost commented Aug 17, 2015

Here we go! I don't know if any of the previous commits failed, but I squashed them regardless.

That Travis failure is from my jumping between lgierth:gateway-host-header and ipfs:gateway-host-header...

@whyrusleeping
Copy link
Member

looks like one of travises OSX machines failed pretty badly. Other than that, the tests look fine.

@jbenet
Copy link
Member

jbenet commented Aug 19, 2015

This LGTM!

jbenet added a commit that referenced this pull request Aug 19, 2015
gateway: make IPNSHostname work on responses too
@jbenet jbenet merged commit 3dfe02a into ipfs:master Aug 19, 2015
@jbenet jbenet removed the status/in-progress In progress label Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants