How to make http node not download a file

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cyber-Kun

so I have 1 http request node that I use for multiple requests.
for some of the requests I need to download the files returned by the request
and for others I don’t

so I noticed if I:

func doupdate(path, url, headers):
	requestname = "update"
	print("doing update")
	self.set_download_file(path)
	self.request(url, headers)

and then do a request that doesn’t need a file to be downloaded:

 func getquota(URL, headers):
	print("gettingquota")
	requestname = "quota"
	print("from getquota()", requestname)
	self.request(URL, headers)

on the “getquota()” function it will download that requests file to the previously set file in the doupdate() function. I was wondering if there is a way to clear the download file path property of the http request node.

initially I thought that if you do a httprequest in a function that sets a download file path that that path would only work in that function but if you then do another request it will overwite the file you previously downloaded with the new request’s body.

currently I work around this by just doing:

func getquota(URL, headers):
	print("gettingquota")
	requestname = "quota"
	print("from getquota()", requestname)
	self.set_download_file("")
	self.request(URL, headers)

so essentially I just set the download file to an empty string. but I’m not sure if this is the “correct way” to go about it

:bust_in_silhouette: Reply From: jgodfrey

While I haven’t used the HttpRequest node in Godot 4, looking at the source code, it seems that the download only happens if the download_file property is not empty (as you noted). So, simply setting it to an empty string (as you’ve done) seems reasonable to me:

ok thank you. I would also like to know if you have the download path set
and the httprequest node emit’s request_completed signal does that mean the download would also be complete?
and then another thing when downloading json files:
the json data is returned as the body of the request_completed signal so I don’t nessecarily have to download it since I could just take the body returned by the http request and save that to a json file?

Cyber-Kun | 2023-03-20 14:27