Skip to content

Commit 9e32081

Browse files
committed
netlib: Supplement the netlib_check_httpconnectivity documentation
A brief introduction to the interface functions, parameters, and return values. Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
1 parent 2a8acac commit 9e32081

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • Documentation/applications/netutils/netlib

‎Documentation/applications/netutils/netlib/index.rst‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ Network Connectivity
344344
345345
- :c:func:`netlib_check_ipconnectivity`
346346
- :c:func:`netlib_check_ifconnectivity`
347+
- :c:func:`netlib_check_httpconnectivity`
347348
348349
.. c:function:: int netlib_check_ipconnectivity(FAR const char *ip, int timeout, int retry)
349350
@@ -388,6 +389,39 @@ Network Connectivity
388389
retrieve the gateway address and then uses :c:func:`netlib_check_ipconnectivity`
389390
to perform the actual ping test.
390391
392+
.. c:function:: int netlib_check_httpconnectivity(FAR const char *host, FAR const char *getmsg, int port, int expect_code)
393+
394+
Check HTTP service connectivity by sending an HTTP GET request and verifying
395+
the response status code. This function establishes a TCP connection to the
396+
specified host and port, sends an HTTP/1.1 GET request for the specified path,
397+
and validates that the server returns the expected HTTP status code.
398+
399+
:param host: Remote hostname or IP address (e.g., ``"www.example.com"`` or
400+
``"192.168.1.1"``). The function supports DNS resolution if
401+
``CONFIG_LIBC_NETDB`` is enabled, otherwise it expects a numeric
402+
IPv4 address.
403+
:param getmsg: URL path for the HTTP GET request (e.g., ``"index.html"`` or
404+
``"api/health"``). An empty string (``""``) requests the root path
405+
(``"/"``). The function automatically prepends a forward slash
406+
to the path.
407+
:param port: TCP port number of the HTTP server (typically 80 for HTTP, or
408+
8080 for alternative HTTP services).
409+
:param expect_code: Expected HTTP status code (e.g., ``200`` for success,
410+
``404`` for not found). The function returns success only
411+
if the server returns this exact status code.
412+
413+
:return: 0 on success (HTTP status code matches expected value). A negative
414+
value on failure, which may be a negative HTTP status code (e.g.,
415+
``-404``) if the server returned a different status code than expected,
416+
or a negative error code (e.g., ``-EINVAL``, ``-ENETUNREACH``) if
417+
connection, DNS resolution, or other errors occurred.
418+
419+
**Note:** This function is blocking and will wait for the HTTP request and
420+
response to complete. The function only reads the first 256 bytes of the HTTP
421+
response to extract the status code. It does not support HTTPS (TLS/SSL) and
422+
only works with HTTP/1.1 servers. The function is useful for HTTP service
423+
health checks, network diagnostics, and automated service monitoring.
424+
391425
ARP Table Support
392426
==================
393427

0 commit comments

Comments
 (0)