HTTP Client Connection Object Setup
Connection's Parameters
µC/HTTP-client provides the function HTTPc_ConnSetParam to configure parameters related to the HTTP Client Connection object. The function takes as argument the type of parameter and the pointer to the parameter. The below parameter's types are available :
Parameter Type | Description |
---|---|
HTTPc_PARAM_TYPE_SERVER_PORT | Sets a specific port for the remote HTTP server. By default the port is set to 80 or to 443 when the Secure module is used. |
HTTPc_PARAM_TYPE_PERSISTENT | Enables the persistent connection mode. The HTTP client will not close the connection at the end of a transaction and will also notified the HTTP server to do the same. The HTTP server must also supports persistent connections for the mode to be functional. Enabling this feature on the HTTP client is no guaranty that a persistent connection with the server will be established but that a best effort will be made. |
HTTPc_PARAM_TYPE_CONNECT_TIMEOUT | Sets the Connect Timeout of the connection. This value represents the time allowed for the connect process to complete. |
HTTPc_PARAM_TYPE_INACTIVITY_TIMEOUT | Sets the Inactivity Timeout of the connection This value represents the time of inactivity allowed on a connection before it is automatically closed. |
HTTPc_PARAM_TYPE_SECURE_COMMON_NAME | Sets the Common Name linked to the HTTP server's SSL Certificate. The Common Name is associated with the SSL Certificate of a web server. The host + domain name is commonly used for the Common Name, ex: "www.example.com" or "example.com". When the HTTP client attempts a secure connection, by default the host name will be used as Common Name. You can use this parameter to specify a different Common Name for a secure connection. |
HTTPc_PARAM_TYPE_SECURE_TRUST_CALLBACK | Sets the callback function to notify the application when a secure connection with a server was made to insure that server certificate is trustworthy. This parameter is mandatory if a secure connection to the server is desired. Therefore, when this parameter is set up, the connection with the server will be automatically a secure one. |
HTTPc_PARAM_TYPE_CONN_CONNECT_CALLBACK | Sets the callback function to notify the application when a connection attempt with the HTTP server is completed. This parameter is mandatory when the |
HTTPc_PARAM_TYPE_CONN_CLOSE_CALLBACK | Sets the callback function to notify the application when an HTTP connection was closed. A connection can be closed by any moment by the HTTP server, or by the client when an unexpected error occurred. A connection will also be closed after any transaction when the persistent mode is not enabled. |
Example
CPU_BOOLEAN HTTPcApp_ConnPrepare (HTTPc_CONN_OBJ *p_conn) { CPU_BOOLEAN persistent; HTTPc_ERR err; /* ---------------- INIT NEW CONNECTION --------------- */ HTTPc_ConnClr(p_conn, &err); if (err != HTTPc_ERR_NONE) { return (DEF_FAIL); } /* ----------------- SET SERVER PORT ------------------ */ port = 8080; HTTPc_ConnSetParam(p_conn, HTTPc_PARAM_TYPE_SERVER_PORT, &port, &err); if (err != HTTPc_ERR_NONE) { return (DEF_FAIL); } /* --------------- SET PERSISTENT MODE ---------------- */ persistent = DEF_YES; HTTPc_ConnSetParam(p_conn, HTTPc_PARAM_TYPE_PERSISTENT, &persistent, &err); if (err != HTTPc_ERR_NONE) { return (DEF_FAIL); } /* --------------- SET CONN'S CALLBACKS --------------- */ #if (HTTPc_CFG_MODE_ASYNC_TASK_EN == DEF_ENABLED) HTTPc_ConnSetParam(p_conn, HTTPc_PARAM_TYPE_CONN_CONNECT_CALLBACK, &AppHTTPc_ConnConnectCallback, &err); if (err != HTTPc_ERR_NONE) { return (DEF_FAIL); } HTTPc_ConnSetParam(p_conn, HTTPc_PARAM_TYPE_CONN_CLOSE_CALLBACK, &AppHTTPc_ConnCloseCallback, &err); if (err != HTTPc_ERR_NONE) { return (DEF_FAIL); } #endif return (DEF_OK); }