BlitzGet Delux and Rerouted addresses

Blitz3D Forums/Blitz3D Programming/BlitzGet Delux and Rerouted addresses

RifRaf(Posted 2009) [#1]
In reference to this code
http://www.blitzbasic.com/codearcs/codearcs.php?code=24

I cannot seem to get it to initiate a link to files through NO-IP (rerouted) address. Direct linking works fine, but I dont want to hardwire my software to a site that may or may not change later.

Any advice would be appreciated. Thanks.


RifRaf(Posted 2009) [#2]
I cannot even connect with OpenTCPStream (webHost$, 80) if the webhost$ is a no-ip redirect.. still stumped.

example
"www.empowergames.com/tt/updates/whatever.dat" will work but
"tinytankupdates.servehttp.com/tt/updates/whatever.dat" will not (no-ip erdirect address)


RifRaf(Posted 2009) [#3]
ok well im on the right track.. for anyone who is wondering, you have to modify blitzget to look at the header to find the word "location" this means the headers info holds the redirected url, you then have to close that connection and start a new one.. heres the info I found on this

14.30 Location
The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request. For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource. The field value consists of a single absolute URI.

Location = "Location" ":" absoluteURI
An example is:

Location: http://www.w3.org/pub/WWW/People.html
Note: The Content-Location header field (section 14.14) differs
from Location in that the Content-Location identifies the original
location of the entity enclosed in the request. It is therefore
possible for a response to contain header fields for both Location
and Content-Location. Also see section 13.10 for cache
requirements of some methods.


heres my modified snipper from blitzget delux.. I send my data to a bank instead of a file. but you can replace my bank with a file handle like the original bgd
Repeat
If WEBGET_ESCAPE=1 Then 
     If KeyDown(1) Then 
          CloseTCPStream www
 	  Return -1
     EndIf  					
EndIf

header$ = Lower$(ReadLine (www))
If Instr(Lower$(header$),"location",1) Then 
     CloseTCPStream www
     spot=Instr(header$,":",1)
     newurl$=Trim$(Mid$(header$,spot+1,Len(header$)-spot))                 
     Return blitzget_bank(newurl$,savebank)
EndIf
If Instr(Lower$(header$),"not found",1) Then 
     closeTCPStream www
     Return -1
EndIf	
DebugLog "hdr: "+header$
If Left (header$, 16) = "content-length: "	; Number of bytes to read
     bytesToRead = Right (header$, Len (header$) - 16)
EndIf
Until header$ = "" Or (Eof (www))




BlitzSupport(Posted 2009) [#4]
Well done, RifRaf... I had a look into this, and found that handling "30x" responses was indeed key to dealing with re-directed URLs -- I've updated my (ahem, 7 year-old) Code Archives entry below (in the comments):

BlitzGet Deluxe

This is better than the original, in that I now check for '200' and '404' responses ('OK to download' and 'file not found' respectively). I've only tested very briefly that it downloads the re-directed URL, and to use this in any sort of production code, you really ought to add much more in the way of error-checking, and ideally ought to re-write from scratch using this only as a general guide to the download process.

This is a great resource if you want to take things further, or handle things more 'correctly'...

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes


RifRaf(Posted 2009) [#5]
Very nice, thank you.