With 4D v19R6, we brought you a new way to perform HTTP requests: HTTP classes. At that time, some of the HTTP classes functionalities were not final, as we wanted to adapt them to the new syntax. It is now done! In v19R7, compressed responses, chunked responses, and redirections functionalities are now complete.
As a bonus, we also added a new way to log HTTP requests. And as it’s helpful to everyone, this new logging is available to the new HTTP classes as well as for the legacy syntax.
First of all, let me speak about the HTTP classes’ functionalities. We have reported and adapted the legacy syntax functioning to fit the new syntax. We include most of its features, namely HTTPs, proxy and server authentication, redirections, chunked responses, and compressed responses. We also added a few functionalities, like the ability to cancel a request or the new logging of HTTP client requests (I’ll come to this in the next paragraph). The last functionality we need to report in the new syntax is the connection persistence through a keep-alive: it will come soon inside a much more prominent feature… that I’ll explain to you in another blog post. Stay tuned!
Now, let’s discuss the new HTTP client logging available in v19R7.
Activating the HTTP client logging is extremely simple; you just have to add this line to your code:
HTTP SET OPTION(HTTP client log; HTTP enable log with all body parts)
And that’s it! All your requests and responses will be logged in the 4DHTTPClientLog_x.txt file in the Logs directory with the same format as the server logs.
Of course, you can log requests and responses entirely, but if you don’t want your log files cluttered with long responses, you can remove the response bodies and even the request bodies. The syntax is extremely close to the server log activation, so you won’t be surprised.
Lastly, here is an example of a request and its response (without their bodies) logged into the HTTP client log file:
# REQUEST # SequenceID: 7 # ConnectionID: DDF30D20070B0848B455971A0D627ED6 # LocalIP: 192.168.18.11:52097 # PeerIP: 192.168.4.7:3128 # TimeStamp: -1607148967 GET http://www.4d.com:80/ HTTP/1.1 Accept-Encoding: gzip, deflate Connection: Close Content-Length: 4 Content-Type: text/plain; charset=UTF-8 Date: Fri, 23 Sep 2022 09:30:58 GMT Host: www.google.com User-Agent: 4D_HTTP_Client/0. [Body Size: 4] # RESPONSE # SequenceID: 6 # ConnectionID: 8EA22B111F16B04B92966DEFAA22704F # LocalIP: 192.168.18.11:52090 # PeerIP: 192.168.4.7:3128 # TimeStamp: -1607191491 # ElapsedTimeInMs: 154 HTTP/1.1 200 OK Cache-Control: private, max-age=0 Connection: close Content-Encoding: gzip Content-Length: 6185 Content-Type: text/html; charset=ISO-8859-1 Date: Fri, 23 Sep 2022 09:30:16 GMT Expires: -1 Via: 1.1 proxy-squid (squid/3.5.27) [Body Size: 6185]
If you have any comments regarding this new feature, feel free to share them with us on the official 4D forum.