Skip to content

Add Network Operations to Standard Library#8

Open
xingzihai wants to merge 1 commit into
urban233:mainfrom
xingzihai:feature/add-network-operations
Open

Add Network Operations to Standard Library#8
xingzihai wants to merge 1 commit into
urban233:mainfrom
xingzihai:feature/add-network-operations

Conversation

@xingzihai

Copy link
Copy Markdown

Summary

This PR adds network operations to HEATHER's standard library, implementing the features requested in Issue #1.

Changes

New Functions Added

  • DownloadFile(const URL, Dest: string): Boolean - Downloads a file over HTTP/HTTPS to the specified destination
  • HttpGet(const URL: string): string - Performs a GET request and returns the response body as a string

Implementation Details

  • Added fphttpclient unit to uHeatherLib.pas for native HTTP support
  • Both functions use TFPHTTPClient from Free Pascal's fphttpclient unit
  • Functions are registered in heather.pas OnCompile method for script access
  • Added test_network.pas demonstrating usage of new functions

Acceptance Criteria Met

DownloadFile function implemented
HttpGet function implemented
✅ Uses native Free Pascal units (fphttpclient)
✅ Both functions registered in THeatherEngine.OnCompile
✅ Test script added demonstrating usage

Testing

The test script test_network.pas can be run with:

heather test_network.pas

It demonstrates:

  • Using HttpGet to fetch webpage content
  • Using DownloadFile to download a file

Resolves #1

Add DownloadFile and HttpGet functions using fphttpclient unit.

- Add fphttpclient to uses clause in uHeatherLib.pas
- Implement DownloadFile: downloads file from URL to local path
- Implement HttpGet: performs HTTP GET request and returns response body
- Register both functions in heather.pas OnCompile method
- Add test_network.pas demonstrating usage

Resolves urban233#1
@urban233

urban233 commented Apr 2, 2026

Copy link
Copy Markdown
Owner

Hi there! Thanks so much for putting this together. Adding network operations is a fantastic step for HEATHER—it really opens up a lot of possibilities for automation.

I took the branch for a spin and did a quick review. The core logic looks solid, but I found a few small things that need a little bit more work before we can merge this in.

1. Small adjustment in uHeatherLib.pas

I noticed that DownloadFile currently fails if you try to download a file directly to the current directory (like DownloadFile(URL, 'test.html')). This happens because ExtractFileDir returns an empty string for simple filenames, and calling ForceDirectories('') returns False, which triggers an early Exit.

We can fix this by only calling ForceDirectories if a path is actually specified:

Dir := ExtractFileDir(Dest);
if (Dir <> '') and not ForceDirectories(Dir) then Exit;

2. Updates for test_network.pas

The test script needs a few tweaks to match how the HEATHER engine currently works:

  • WriteLn vs Print: The engine has Print registered, but WriteLn isn't recognized yet.
  • Print Arguments: Currently, our Print implementation only takes a single string, so we'll need to concatenate arguments with +.
  • Missing Helpers: IntToStr isn't registered in the engine's standard library yet, so we might want to keep the test simple for now.

3. A Note on HTTPS/SSL

Since TFPHTTPClient is used for the HTTPS requests in your test, it requires OpenSSL libraries to be present on the system. It might be worth adding a small note in the documentation or the README about this dependency so users know why an HTTPS request might fail silently if they don't have the DLLs/libs installed.


Here is a simplified version of the test script that I verified works with the current engine:

program test_network;

begin
  Print('=== HEATHER Network Operations Test ===');
  Print('Testing HttpGet...');
  if Length(HttpGet('http://example.com')) > 0 then
    Print('HttpGet success!')
  else
    Print('HttpGet failed.');
  
  Print('Testing DownloadFile...');
  if DownloadFile('http://example.com', 'downloaded_example.html') then
    Print('Download successful!')
  else
    Print('Download failed.');
end.

Overall, this is a great addition! If you can update the DownloadFile logic and the test script, I think we’re in a great spot to get this merged. Keep up the awesome work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Network Operations to Standard Library (HTTP GET/POST, Download)

2 participants