HEAD request not found in Web component

62 views
Skip to first unread message

JMP Ya

unread,
Sep 19, 2019, 11:04:23 PM9/19/19
to MIT App Inventor Forum
I´m try to check if exist a new version of my app, then I search options and read about this request HEAD, testes with Postman and result is OK, you can check if file exist without download it. But itsnot implemented into Web component  ,who improve thats component ?

Thanks in advance.

PD: If anyone know other way to check if file exist in one server , please let me know !!! :)

TimAI2

unread,
Sep 20, 2019, 3:49:56 AM9/20/19
to MIT App Inventor Forum
Is this on your own server and not on Play Store ?

If so you could set a flag in a file to check - e.g. use a google sheet with a list of versions or just a single cell with latest version number, test that against current version number

Taifun

unread,
Sep 20, 2019, 5:39:38 PM9/20/19
to MIT App Inventor Forum
If anyone know other way to check if file exist in one server 

you could use the ftp extension and its RemoteFileNames method to get filenames of a remote directory

remoteFileNames.JPG



Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Evan Patton

unread,
Sep 24, 2019, 7:56:53 PM9/24/19
to MIT App Inventor Forum
If the server is configured correctly to handle HTTP headers, you could use Get with a If-Modified-Since header and the date you last checked. Typically, the server will return a 304 Not Modified if the file hasn't changed. Otherwise, 200 OK will be sent along with the new contents. It would save you the trouble of having to do a HEAD then a GET if there is a valid change.

Regards,
Evan

TimAI2

unread,
Sep 25, 2019, 4:15:39 AM9/25/19
to MIT App Inventor Forum
Some example header blocks would be useful.... ;)

Chris Ward

unread,
Sep 25, 2019, 5:11:10 AM9/25/19
to MIT App Inventor Forum

Chris Ward

unread,
Sep 25, 2019, 5:26:07 AM9/25/19
to MIT App Inventor Forum
or:

If Modified Since 2.png




TimAI2

unread,
Sep 25, 2019, 5:29:24 AM9/25/19
to MIT App Inventor Forum
OK, you sent that off with your web1.get, then test the response code for a 304 ?
Assume the requested file will not be "sent" if a 304 ?

Chris Ward

unread,
Sep 25, 2019, 5:40:48 AM9/25/19
to MIT App Inventor Forum
When the App is installed, It should either save a date instance or a fully formatted http date. Each time the App is run, the instance/date can be sent to the server - if a file of later date is available, receive a 200, else a 304.

Chris Ward

unread,
Sep 25, 2019, 5:41:26 AM9/25/19
to mitappinv...@googlegroups.com
... If a 200, GET the file.

Chris Ward

unread,
Sep 25, 2019, 5:55:54 AM9/25/19
to MIT App Inventor Forum
So, something like this (sorry, not tested!)

GetFile.png


Taifun

unread,
Sep 25, 2019, 8:41:12 AM9/25/19
to MIT App Inventor Forum
you should remove the : 

Unbenannt.JPG


Taifun

TimAI2

unread,
Sep 25, 2019, 9:27:41 AM9/25/19
to MIT App Inventor Forum
How I read it the blocks will still download the file...?

save response = true has to be set, and file has been "got"  before we test the response code ?

Chris Ward

unread,
Sep 25, 2019, 9:40:07 AM9/25/19
to MIT App Inventor Forum
.... I think the download will only occur if the file has been modified since the given date-time. Let's see what happens with JMP's file.

Chris Ward

unread,
Sep 25, 2019, 10:14:33 AM9/25/19
to mitappinv...@googlegroups.com
@ Taifun it (:) is used in the Mozilla example.......

Edit: Do you mean App Inventor is going to insert it?

TimAI2

unread,
Sep 25, 2019, 10:38:21 AM9/25/19
to MIT App Inventor Forum
@ Evan

Can we send a HEAD request in AI2 ?

TimAI2

unread,
Sep 25, 2019, 11:03:22 AM9/25/19
to mitappinv...@googlegroups.com
@ Chris

This is just returning a 200 code and downloading the file

blocksheadtest.png


(I tried without the colon, and without the Since!, and with a GMT in the date))


TimAI2

unread,
Sep 25, 2019, 11:28:11 AM9/25/19
to MIT App Inventor Forum
@ Chris

I got a 304 response with this:

blocksgot304.png


TimAI2

unread,
Sep 25, 2019, 11:33:52 AM9/25/19
to MIT App Inventor Forum
Looks like two web components are needed, one to test and one to download if test passes....

Taifun

unread,
Sep 25, 2019, 1:01:16 PM9/25/19
to MIT App Inventor Forum
it (:) is used in the Mozilla example.......
Edit: Do you mean App Inventor is going to insert it?

yes exactly, App Inventor uses list of lists...
Taifun

Chris Ward

unread,
Sep 25, 2019, 4:26:19 PM9/25/19
to MIT App Inventor Forum
Hi Tim

I think it might be Server side. To quote Evan: "If the server is configured correctly to handle HTTP headers".

TimAI2

unread,
Sep 25, 2019, 5:11:15 PM9/25/19
to MIT App Inventor Forum
My server IS handling http requests correctly, it is just how the AI2 handles them that is the issue :)

As I previously said, the web component set to download a file gets the file before we can access the response code, therefore it returns a 200 we already have the file.
By using the web1.got text, we can get the server response based on the header request.

Evan Patton

unread,
Sep 25, 2019, 5:28:20 PM9/25/19
to MIT App Inventor Forum
The point is that if you get a 304, then there shouldn't be any body content so it will just save an empty file. If the server returns a 200, then it will also send the content, which will be stored in the file. If this is an APK file, then you can use the filename to launch the package installer. I don't see why you need two web components here.

Regards,
Evan

TimAI2

unread,
Sep 25, 2019, 5:34:05 PM9/25/19
to MIT App Inventor Forum
In my testing, if save response = true, then you have to use the web1.gotfile block, the web1.gottext block errors out.
If you have got the file, then it is too late, regardless of the response code.

Evan Patton

unread,
Sep 25, 2019, 5:52:48 PM9/25/19
to MIT App Inventor Forum
Specifically, GotFile is run after the contents of the response are saved to the named file. It does not necessarily mean that the actual contents of the URL were retrieved. If there were no contents (e.g., HTTP 304), then the file should be truncated. You can still use the responseCode parameter of the GotFile event to determine what to do with the file (including ignoring it).

Regards,
Evan

TimAI2

unread,
Sep 25, 2019, 6:06:23 PM9/25/19
to MIT App Inventor Forum
Yes, a bit of fiddling around with dates/date formats returned a 304 using gotFile.
It does create a file but an empty one, which could be confusing, and will overwrite
the existing file !! Probably not what the OP wants.

TimAI2

unread,
Sep 25, 2019, 6:31:25 PM9/25/19
to MIT App Inventor Forum
Requires a specific date/time format:

headerstimeformat.png


Chris Ward

unread,
Sep 25, 2019, 7:02:22 PM9/25/19
to MIT App Inventor Forum
Given Tim's test results, I think the following would be safer:

1) On first run, save the App Version Code to TinyDB
2) On subsequent runs:

   a) Get the App Version Code from TinyDB
   b) GET text of file version.txt from Server
   c) If version from file version.txt > version from TinyDB: GET updated file (example: APK) from Server and save new App Version Code to TinyDB

JMP Ya

unread,
Sep 28, 2019, 11:21:04 PM9/28/19
to MIT App Inventor Forum
Many many thanks to all you people, about the current version, that is available with some extension from app itself, so its not necesary to use any DB.

And YES, the dummy .TXT file seems to be the simplest solution.

Thanks a lot !
Reply all
Reply to author
Forward
0 new messages