mIRC Home    About    Download    Register    News    Help

Print Thread
$urlget redirection #267922 19/10/20 01:04 PM
Joined: Jan 2004
Posts: 1,306
L
Loki12583 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,306
1. Add option to disable redirects. Following a redirect loses the original response (with set-cookie headers required for authentication). You dismissed the idea of following infinite redirects here but maybe we can use -d0 for no redirects instead.

2. Add support for Protocol-relative redirects (//uri).

Quote
url      https://forums.mirc.com/ubbthreads.php
redirect https://forums.mirc.com:443//forums.mirc.com/ubbthreads.php/forum_summary
method   post
type     binvar
target   &response
alias    urlget.callback
id       1025
state    fail
size     0
resume   0
rcvd     0
time     2610
reply    HTTP/1.1 404 Not Found
Date: Mon, 19 Oct 2020 12:37:47 GMT
Server: Apache
Vary: User-Agent
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8


Code
alias Forum.Login {
  var %forumuser = xxx
  var %forumpass = xxx
  
  bset -t &body 1 ubb=start_page&Loginname= $+ %forumuser $+ &Loginpass= $+ %forumpass $+ &rememberme=1&firstlogin=1&ocu=%2F%2Fforums.mirc.com%2Fubbthreads.php%2Fforum_summary&buttlogin=Log+In
  bset -t &headers 1 Content-Type: application/x-www-form-urlencoded
  
  var %url = https://forums.mirc.com/ubbthreads.php
  
  noop $urlget(%url, pb, &response, urlget.callback, &headers, &body)
}

alias urlget.callback {
  var %id = $1

  echo -ag -
  echo -agi9 url      $urlget(%id).url
  echo -agi9 redirect $urlget(%id).redirect
  echo -agi9 method   $urlget(%id).method
  echo -agi9 type     $urlget(%id).type
  echo -agi9 target   $urlget(%id).target
  echo -agi9 alias    $urlget(%id).alias
  echo -agi9 id       $urlget(%id).id
  echo -agi9 state    $urlget(%id).state
  echo -agi9 size     $urlget(%id).size
  echo -agi9 resume   $urlget(%id).resume
  echo -agi9 rcvd     $urlget(%id).rcvd
  echo -agi9 time     $urlget(%id).time
  echo -agi9 reply    $urlget(%id).reply

  if ($urlget(%id).type == binvar) && ($bvar($urlget(%id).target,0)) {
    echo -agi9 response $bvar($urlget(%id).target,1-3000).text
  }
}

Last edited by Khaled; 20/10/20 08:24 AM.
Re: $urlget redirection [Re: Loki12583] #267930 20/10/20 11:08 AM
Joined: Dec 2002
Posts: 4,841
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,841
Quote
2. Add support for Protocol-relative redirects (//uri).

RIghteo. I haven't found any references to this. Do you have a reference to the RFC for this? And possibly some real world examples?

Is it as simple as using "//forums.mirc.com/ubbthreads.php/forum_summary method post" as the new URL?

Tested this with the example script you provided and it seemed to work.

Re: $urlget redirection [Re: Khaled] #267932 20/10/20 12:11 PM
Joined: Jan 2004
Posts: 1,306
L
Loki12583 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,306
Its purpose is just to keep the same scheme/protocol. So http goes to http, https goes to https.

If the original URL was http and you receive a redirect "//forums.mirc.com/ubbthreads.php/forum_summary" the new effective url would be http://forums.mirc.com/ubbthreads.php/forum_summary
If the original URL was https with the same redirect "//forums.mirc.com/ubbthreads.php/forum_summary" the new effective url would be https://forums.mirc.com/ubbthreads.php/forum_summary


You can see this forum does it on a redirect, if you look at the source of https://www.reddit.com you can see a bunch of resources use this format href="//


https://tools.ietf.org/html/rfc1808


Quote
URL = ( absoluteURL | relativeURL ) [ "#" fragment ]

absoluteURL = generic-RL | ( scheme ":" *( uchar | reserved ) )

generic-RL = scheme ":" relativeURL

relativeURL = net_path | abs_path | rel_path

net_path = "//" net_loc [ abs_path ]
abs_path = "/" rel_path
rel_path = [ path ] [ ";" params ] [ "?" query ]

Last edited by Loki12583; 20/10/20 12:25 PM.
Re: $urlget redirection [Re: Khaled] #267936 20/10/20 08:05 PM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
Not exactly the same as following redirects but this is fairly common behavior with browsers when they follow links

Assume we are on https://site.com, the following HTML link would direct the user to https://site.com/page.

Like wise, if we are on http://site.com, the following would direct the user to http://site.com/page


Code
<a href="//site.com/page2">
    Download
</a>


For intents and purposes, its basically a way to say "use the same protocol you previously used"


I am SReject
My Stuff
Re: $urlget redirection [Re: Loki12583] #267943 21/10/20 08:53 PM
Joined: Dec 2002
Posts: 4,841
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,841
Quote
1. Add option to disable redirects. Following a redirect loses the original response (with set-cookie headers required for authentication). You dismissed the idea of following infinite redirects here but maybe we can use -d0 for no redirects instead.

What would you want $urlget() to do if a redirect is sent in this case?

Re: $urlget redirection [Re: Khaled] #267944 21/10/20 09:13 PM
Joined: Jan 2004
Posts: 1,306
L
Loki12583 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,306
Just hand back the headers and body like any other response

Re: $urlget redirection [Re: Khaled] #267948 22/10/20 01:43 AM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
To give more details on Loki's post:

Essentially you'd return the content of the response(that is the response saying to redirect to another resource) to $urlget the same way you would if the host had returned a 200 OK response

Assume the following client<->server interaction takes place
Code
<- GET / HTTP/1.1
<- Host: site.com

-> HTTP/1.1 302 Found
-> Location: https://site.com/index.html
-> Content-Length: 0


With the above assumption, the following would occur
Code
alias example {

  ;; R0 indicates no redirects should be followed
  noop $urlget(https://site.com, gbR0, &bvar, example_callback)
}

alias example_callback {

  ;; Reply: HTTP/1.1 302 Found\r\nLocation: https://site.com/index.html\r\nContent-Length: 0
  echo -ag Reply: $urlget($1).reply
}

Last edited by FroggieDaFrog; 22/10/20 01:44 AM.

I am SReject
My Stuff
Re: $urlget redirection [Re: FroggieDaFrog] #267984 26/10/20 09:44 PM
Joined: Jan 2004
Posts: 1,306
L
Loki12583 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,306
New 'k' switch and relative redirect confirmed to work on beta 1807

Re: $urlget redirection [Re: Loki12583] #267985 26/10/20 10:44 PM
Joined: Dec 2002
Posts: 4,841
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,841
Great, thanks for confirming.