C library for easier HTTP(S)
Chris Mahoney (1684) 2165 posts |
The other day I mentioned that I was working on a library that made it easier to use the URL, AcornHTTP and AcornSSL modules. I said at the time that it wasn’t quite ready but that I’d share something in “a few days”. It’s been more than a few days so I figured that I should share what I have. Download HTTPLib – Click the HTTPLib tab. This should be considered “alpha” quality. Source is linked from the same page. Quick overview
You will also need to add some code to your polling loop using
Remember to set the mask back to something appropriate afterwards :) Downloading files
The downloaded file will have its file type set based on its MIME type. As of HTTPLib 0.06 you can cancel an in-progress download by calling Setting user agent Other functions Limitations
Future plans
Licence Upgrading to 0.09 I’ll post any updates in this thread. Hopefully someone finds this useful and easier than massaging the SWIs directly. And almost forgot to say: I think you’ll need AcornHTTP 0.98 or newer. Earlier versions will probably not work. You’ll also need the URL module loaded, and you will of course need AcornSSL if you’re using HTTPS. |
Rick Murray (539) 13850 posts |
Why does nobody seem to understand THAT A BIG WALL OF TEXT IN CAPITAL LETTERS IS HARDER TO READ? Imagine reading the licence aloud AND SHOUTING the large chunk at the end… |
Steve Pampling (1551) 8172 posts |
Imagine a user that emails the third line techs direct with BOLD UPPERCASE AND RED. |
Chris Mahoney (1684) 2165 posts |
Well, for 0.02 I’ll put the licence inside the Zip so you don’t need to be blasted with it (in this case I forgot to include it and I’d already copied the Zip onto my server). With that said, I think the licence file in my other apps is probably also full of caps because I just copied a template. I’ll make a note to change that… |
Steve Pampling (1551) 8172 posts |
I’m pretty sure Rick’s comment was a criticism of the person/people that wrote the original. |
Colin Ferris (399) 1818 posts |
With ref to the code – might be nice if it could be put into a module – so it could be used from BASIC etc. Thanks for the work. |
Chris Mahoney (1684) 2165 posts |
I know, but still :) As for work, we have someone who writes every single email subject line in all caps (but thankfully not the rest of the message!)
While that would be possible, I’m not sure how much benefit it would be. The URL module already exists, and HTTPLib is basically a simplified C interface into that. If there are specific features you’d find useful in BASIC then it might be more logical to add them to URL rather than have a module “wrapping” another module (which, in turn, wraps the AcornHTTP module!) If you disagree then please give some examples of what you’d like to accomplish so I can understand better. |
Clive Semmens (2335) 3276 posts |
My impression was the whole purpose of C was to get everyone playing an endless game of Pass The Parcel… |
Steffen Huber (91) 1953 posts |
Sensible future RISC OS project number 87536: teach BASIC to load and call a user-mode library (ELF, ALF) so that we can stop putting standard application code into the RMA and excecute it with OS privileges. I am sure Steve will be around in a minute and tell us that Basalt can do this already :-) |
patric aristide (434) 418 posts |
Lol! |
Steve Drain (222) 1620 posts |
Not yet. ;-) I did play around with calling SharedCLib routines within Basalt, to enhance printing with I understand the point about privileged modes, but I still like the parsimony of shared routines called as SWIs. |
Rick Murray (539) 13850 posts |
We all do, but this is one of the things we’re stuck with – unless somebody fancies having a crack at running user (and most system) modules in SYS mode . . . and dealing with the fallout of pretty much everything that assumes “modules run in SVC mode”.
Indeed. While SWIs have efficiency issues (recalling the SWI number from something that should be in the code cache, not the data cache etc), there is a benefit to a set of routines that can be called via a standardised interface from just about any language worth knowing the name of1. 1 Obviously I am referring to the subset of languages available on RISC OS, not languages in general everywhere (and especially not the vagaries of human languages!)… |
Chris Mahoney (1684) 2165 posts |
HTTPLib 0.02 is now available, and the first post has been updated accordingly. But in summary:
|
Chris Mahoney (1684) 2165 posts |
HTTPLib 0.03 is now available. Changes in this version:
|
Chris Mahoney (1684) 2165 posts |
HTTPLib 0.04 is now available. This one fixes an embarrassing bug which was intermittently corrupting downloaded files (because some numpty – me – was calling the wrong SWI…) and adds an httplib_head function for doing a HEAD request. There is still an issue with some servers not “liking” HTTPLib, which I’ll hopefully get to the bottom of in 0.05. |
Chris Mahoney (1684) 2165 posts |
Version 0.05 is now available (see first post). It supports the rest of the HTTP methods, and is also “better” because it doesn’t have the same code repeated all through it anymore :) The issue I mentioned in the previous post appears to be a problem with AcornHTTP rather than HTTPLib. I haven’t had a chance to investigate it properly yet. |
John Sandgrounder (1650) 574 posts |
where? How do we use it? |
Chris Mahoney (1684) 2165 posts |
It’s included in the nightly HD4 image and the docs are here. |
John Sandgrounder (1650) 574 posts |
Thank you. |
Chris Mahoney (1684) 2165 posts |
HTTPLib has been updated to version 0.06 (link in first post).
|
Chris Mahoney (1684) 2165 posts |
0.07 released. This version has some minor reliability improvements and is now known to work when called from a module. |
Sergey Lentsov (8268) 63 posts |
The link from first message return 404 error. |
nemo (145) 2556 posts |
|
Chris Mahoney (1684) 2165 posts |
Apologies! I moved the site yesterday and completely forgot that I had direct links to some of the Zips. Links in first post fixed, although I’ve broken nemo’s link in the process :) |
Michael Gerbracht (180) 104 posts |
Does anybody have a C or C++ example app that uses HTTPLib? I can’t get it to work although I tried to implement it as shown in the initial post. But I am new to C so the problem is very likely me ;-) |