MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 430 forks source link

internet.request location property #1726

Closed Fingercomp closed 6 years ago

Fingercomp commented 8 years ago

That would be useful if request gets redirected so I could easily get an URL it was redirected to. Ex.:

request = internet.request(url)
location = request.location
fnuecke commented 8 years ago

Can't you get that from the response headers?

local _,_,headers = request.response()
doSomethingWith(headers['Location'])

Or something like that?

Fingercomp commented 8 years ago

OpenComputers automatically redirects requests if a server tells so. Screenshot of OC screen with me trying to get "Location" header There is no "Location" header. And none of those headers contain URL.

fnuecke commented 8 years ago

Uhh, that's Java's doing then though, dunno if that can be disabled?

Kubuxu commented 8 years ago

Looks like you can: http://stackoverflow.com/a/2659022

fnuecke commented 8 years ago

Cool. Then the only remaining question is: new parameter or make that the default? Probably the former for less breakage, I guess.

payonel commented 6 years ago

I'd actually prefer we not try to handle redirects ourselves. I suppose if someone PRs this and the work looks reliable I'd consider it. But I'd prefer we leave it alone

skyem123 commented 6 years ago

@payonel, it sounds like you misread this one, this is kinda about letting OC not do the redirect. :P

payonel commented 6 years ago

@skyem123 i understand, but I didn't explain myself well. If java doesn't do the redirect, then OC will have to, or openos will, or user code will. Someone will, and I'd prefer to leave that to our java libraries we are using.

skyem123 commented 6 years ago

True, but why not make it an optional thing? Allows a level between "raw TCP" and "HTTP doing everything automagicaly". :p