Electronic device, control method, and storage medium
An electronic device publishes an application programming interface (API) for a setting related to CORS in which a setting that is related to enabling or disabling of cross-origin resource sharing (CORS) is included, and in a case where a Hypertext Transfer Protocol (HTTP) request for the API is received from another device, executes the setting related to CORS based on the request.
1 . An electronic device comprising:
one or more processors; and
one or more memories that store computer-readable instructions for causing, when executed by the one or more processors, the electronic device to perform operations comprising:
functioning as a web server;
providing, to an external device, Web Application Programming Interfaces (WEB APIs) including at least a cross-origin resource sharing (CORS) enablement-setting WEB API for switching whether to enable or disable CORS in the web server from outside via a Hypertext Transfer Protocol (HTTP) request and an allowed-origin-setting WEB API for accepting information that designates an allowed origin under CORS, the allowed-origin-setting WEB API being different from the CORS enablement-setting WEB API; and
enabling the CORS in response to receiving a first HTTP request in which a first Uniform Resource Locator (URL) of the CORS enablement-setting WEB API is designated and a first argument indicating that the CORS is to be enabled is designated,
wherein the CORS enablement-setting WEB API is configured not to accept information designating an allowed origin.
2 . The electronic device according to claim 1 , wherein the operations further comprise disabling the CORS in response to receiving a second HTTP request in which the first URL of the CORS enablement-setting WEB API and a second argument indicating the CORS is to be disabled,
wherein the first argument consists only of a character string {“value”: “enable”} described in a Javascript Object Notation (JSON) format, and the first HTTP request includes no other argument except for the first argument, and
wherein the second argument is an argument consisting of a character string {“value”: “enable”} described in the JSON format, the second HTTP request includes no other argument except for the second argument.
3 . The electronic device according to claim 1 , wherein
the operations further comprise performing setting that allows a response for an HTTP request from an origin designated by a third HTTP request directed to the allowed-origin-setting WEB API.
4 . The electronic device according to claim 1 , wherein
in the providing the WEB APIs, a third WEB API for accepting information that designates an allowed header according to CORS is provided, and
the operations further comprise performing a setting that allows a response for an HTTP request that includes a header designated in a fourth HTTP request for the third API has been received.
5 . The electronic device according to claim 1 , wherein
in a case where an authentication function is enabled in the electronic device, the first HTTP request for the CORS enablement-setting WEB API is allowed, and in a case where the authentication function is not enabled in the electronic device, the first HTTP request for the CORS enablement-setting WEB API is not allowed.
6 . The electronic device according to claim 1 , wherein
a setting of enablement of the CORS is stored in a work memory, and
in a case where a power state of the electronic device in which the CORS is enabled is changed to a power-off state and then the electronic device is transitioned to a power-on state, operation as the web server is started in an initialized state in which the CORS is disabled.
7 . The electronic device according to claim 6 , wherein the electronic device is handheld device.
8 . The electronic device according to claim 6 , wherein the electronic device is camera device.
9 . A control method to be executed by an electronic device, the method comprising:
functioning as a web server;
providing, to an external device, Web Application Programming Interfaces (WEB APIs) including at least a cross-origin resource sharing (CORS) enablement-setting WEB API for switching whether to enable or disable CORS in the web server from outside via a Hypertext Transfer Protocol (HTTP) request and an allowed-origin-setting WEB API for accepting information that designates an allowed origin under CORS, the allowed-origin-setting WEB API being different from the CORS enablement-setting WEB API; and
enabling the CORS in response to receiving a first HTTP request in which a first Uniform Resource Locator (URL) of the CORS enablement-setting WEB API is designated a first argument indicating that the CORS is to be enabled is designated,
wherein the CORS enablement-setting WEB API is configured not to accept information designating an allowed origin.