web.server
web.server
Function
Read request and server information.
Syntax
web.server
Parameters
No parameters.
Return value
| Type | Description |
|---|---|
| Object | Returns the current HTTP request and connection information object. |
Object structure
| Field | Type | Description |
|---|---|---|
| method | String | The current request method, usually an uppercase string such as GET, POST, PUT, DELETE, etc. |
| version | String | HTTP protocol version debugging text, such as HTTP/1.1, HTTP/2.0. |
| scheme | String | Request protocol, usually http or https. |
| headers | Object | Request header object; the key is the request header name, and the value is the request header string value. |
| local_addr | String | Server local listening address, including IP and port. |
| remote_addr | String | Client remote address, including IP and port. |
| ip | String/Null | Client IP string; returns null if the underlying request cannot resolve the IP. |
| port | Int/Null | Client port; returns null if the underlying request cannot resolve the port. |
Example
result = web.server.method // Output: GET print result
Read the request header and client address:
ua = web.server.headers['user-agent'] ip = web.server.ip port = web.server.port echo(ip + ':' + string(port))
Notes
-
web.methodandweb.server.methodreturn the same request method string. - The
headersfield only reads client request headers; please useweb.header()to set response headers. - The request header name is generated by the underlying HTTP service, and should be based on the actual object key name before accessing.