picosh / pico

hacker labs - open source and managed web services leveraging SSH
https://pico.sh
MIT License
785 stars 27 forks source link

Testing issues with redirects on pgs #91

Closed josephbu closed 7 months ago

josephbu commented 7 months ago

Using an example _redirect file and testing.

$ cat _redirects 
/wow     /index.html     301

If I do a curl against /wow I get a 404.

$ curl -v https://jb-test.pgs.sh/wow

> GET /wow HTTP/2
> Host: jb-test.pgs.sh
> user-agent: curl/7.81.0
> accept: */*

404 not found

If instead I do a curl against //wow, with the extra / I see the redirect happen.

$ curl -v https://jb-test.pgs.sh//wow

> GET //wow HTTP/2
> Host: jb-test.pgs.sh
> user-agent: curl/7.81.0
> accept: */*

< HTTP/2 301 

Next test is removing the status code, so the _redirect file is just a from and to:

$ cat _redirects 
/wow     /index.html

With the status code removed from the file, the entire site will just give http 502 error, regardless of the query, eg.

$ curl -v https://jb-test.pgs.sh/wow

> GET /wow HTTP/2
> Host: jb-test.pgs.sh
> user-agent: curl/7.81.0
> accept: */*

< HTTP/2 502 

If I put a status code back, but instead change the destination to a URL or to just /, I'll only get a 404.

Either of these:

$ cat _redirects 
/wow     https://jb-test.pgs.sh     301
$ cat _redirects 
/wow     /     301

Result in:

$ curl -v https://jb-test.pgs.sh/wow

> GET /wow HTTP/2
> Host: jb-test.pgs.sh
> user-agent: curl/7.81.0
> accept: */*

404 not found
$ curl -v https://jb-test.pgs.sh//wow

> GET //wow HTTP/2
> Host: jb-test.pgs.sh
> user-agent: curl/7.81.0
> accept: */*

404 not found

Maybe some issues parsing /?

I'm happy to do more testing if it's needed, due to TZ difference I figured might be easier raising here than IRC.

neurosnap commented 7 months ago

Hi! Thanks the detail report. I think I have fixed all of these issues, could you try some of them again to confirm?

josephbu commented 7 months ago

@neurosnap Thank you!

I've checked and most of the examples are fixed, however when redirecting to a complete URL I still get a 404.

Tested with the below redirect settings.

$ cat _redirects 
/wow     https://jb-test.pgs.sh     301
$ cat _redirects 
/wow                 https://wow.com
neurosnap commented 7 months ago

Oops, looks like I missed that use case, should be fixed: https://github.com/picosh/pico/commit/de1beb00f2ffcb4896ceb91856437ff2f1e501d2

Can you try one more time? Thanks again!

josephbu commented 7 months ago

Looks good, testing this one:

$ cat _redirects 
/wow       https://wow.com

Just confirming that the expected behavior here is to generate OK as the text with a hyperlink to the redirection URL?

$ curl -v https://jb-test.pgs.sh/wow

> GET /wow HTTP/2
> Host: jb-test.pgs.sh
> user-agent: curl/7.81.0
> accept: */*

< HTTP/2 200 

* TLSv1.2 (IN), TLS header, Supplemental data (23):
<a href="https://wow.com">OK</a>.

With a http code included in the redirect file, it redirects fine and doesn't print the example output with hyperlink.