This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Espen's profile picture

Set HTTP request properties

Started by Espen, 21 November 2012 - 05:15 PM
Espen #1
Posted 21 November 2012 - 06:15 PM
Suggestion: Include the ability to set request properties for http.request()

http.request( url, postData, ... )
where '…' can be strings, each defining a property, like e.g.:
http.request( "http://www.example.com/index.php", "var1=foo&var2=bar", "User-Agent: Mozilla/5.0", "Content-Type: image/jpeg")

This would allow one to change e.g. the default Java User-Agent to a customized one.
Without this ability, certain websites are not accessible due to blocking requests with unsupported User-Agent strings, as discussed here:
[topic='6209']http not working for google search[/topic]
Sammich Lord #2
Posted 21 November 2012 - 08:46 PM
I love this idea! It should be added since there is no obvious security holes like other suggestions.
TehSomeLuigi #3
Posted 26 November 2012 - 12:04 AM
Also, : COOKIE SUPPORT.
Yes, I really want cookies.
Left4Cake #4
Posted 12 December 2012 - 11:06 AM
I second Cookie Support, I tried to use Sessions for something but then learned that Sessions also require Cookies.
AfterLifeLochie #5
Posted 14 December 2012 - 08:36 PM
I think this is definitely a good idea.

If this doesn't get added (or considered), I suppose I or someone can pick it up as a peripheral - although I'd have no idea as to what I'm doing, as I haven't actually done any really serious modding. No better time to learn, I suppose!
Cloudy #6
Posted 14 December 2012 - 10:51 PM
I'll look into it :-)
Espen #7
Posted 12 April 2013 - 06:45 AM
Hey Cloudy, did you by any chance have the opportunity to take a look at it yet?
Being able to build a custom header per request would greatly extend the ability of POST requests.
Just curious and wanted to refresh your memory in case you forgot about it, no pressure.
Though I'd highly appreciate it of course. ^_^/>
zekesonxx #8
Posted 12 April 2013 - 08:19 AM
You don't need to code in cookie support Cloudy. Just put in header support, cookies are just headers after all.
Xfel #9
Posted 13 April 2013 - 12:27 AM
I think the problem is: If you it call like

http.post("<someaddress>", { xy="Hello World!" } )
they would need to pass a TABLE as argument to a JAVA METHOD. And for some reason they don't want to implement it.
Cloudy #10
Posted 13 April 2013 - 12:59 AM
I think the problem is: If you it call like

http.post("<someaddress>", { xy="Hello World!" } )
they would need to pass a TABLE as argument to a JAVA METHOD. And for some reason they don't want to implement it.

It is planned, we've just not done it yet.
Espen #11
Posted 13 April 2013 - 05:08 AM
I think the problem is: If you it call like

http.post("<someaddress>", { xy="Hello World!" } )
they would need to pass a TABLE as argument to a JAVA METHOD. And for some reason they don't want to implement it.

But we don't necessarily need to pass the header properties as a table. Shouldn't it be possible to provide the header properties as a sequence of arguments rather than an array/table? Like so:
http.post("<someaddress>", "<post data>", "<header property 1>", "<header property 2>", "<header property 3>" )

Then, Java-side, we simply look if there are more than two arguments, and if there are, we iterate through them and set the HTTP header properties as given.
I mean, isn't that basically what we can even do with the peripheral API already? I.e. to read a sequence of Lua arguments into a Java Object array?
I haven't looked at the code for the HTTP API yet, so I don't know if it is handled differently there than the peripheral API does.^^

It is planned, we've just not done it yet.
That's nice to know, thx for the info. :)/>
Edited on 13 April 2013 - 03:09 AM