LiHaSo Webserver Modul
Find a file
2024-09-17 10:52:42 +02:00
build_tools Build Tools Update 2023-03-29 10:38:48 +02:00
cfg new install standards 2023-03-30 15:47:31 +02:00
inc Add ICO mimetype 2024-03-13 09:24:00 +01:00
lhs_lib@e6d5b2a00a new lhs_lib 2024-09-17 10:52:42 +02:00
testweb Diverse Testfiles 2020-11-08 23:36:44 +01:00
.gitignore new install standards 2023-03-30 15:47:31 +02:00
.gitmodules changed submodule to https 2022-02-17 13:40:53 +01:00
default_http_status_codes.xml Status and Config XML uploaded 2023-03-29 10:39:26 +02:00
installation.pb Installation Fix and Cleanup 2024-03-11 10:10:20 +01:00
lhttpd.pb Bugfixes 2024-03-13 09:23:28 +01:00
LICENSE Initial commit 2020-10-28 14:24:53 +01:00
lweb.pbi Add HTTP request methods abd Debug for sucessfull Library Load 2024-03-15 13:27:20 +01:00
lweb.pbp Bugfixes 2024-03-13 09:23:28 +01:00
lweb_auth.pb Bugfixes 2024-03-13 09:23:28 +01:00
lweb_header.pbi add lhs_web_helper lib to lweb_header 2023-03-31 10:08:28 +02:00
README.md Add more parameters to the document 2021-05-17 17:31:13 +02:00
README_DE.md Deutsch Original 2021-05-11 11:54:59 +02:00
server_example.pb Bugfixes 2024-03-13 09:23:28 +01:00
server_example_function.pbi Remove the post_test handler 2023-03-29 20:03:17 +02:00
server_example_function_library.pb Use the lhs_lib helper library now 2023-03-30 08:28:45 +02:00
TODO.txt Update old TODO list 2023-03-31 08:49:32 +02:00

lweb

LiHaSo Webserver Modul

Public functions:

Server module configuration:

Parameter List:

HTTP Server Configuration:
lweb::#conf_HTTP_port            ; Listening Port
lweb::#conf_HTTP_binding         ; Interface binding e.g. only localhost with "127.0.0.1"
lweb::#conf_max_HTTP_clients     ; Max connected Clients to the HTTP Server

HTTPS Server Configuration:
lweb::#conf_HTTPS_Port           ; Listening Port
lweb::#conf_HTTPS_Binding        ; Interface binding e.g. only localhost with "127.0.0.1"
lweb::#conf_HTTPS_CA             ; eg. "fullchain.pem"
lweb::#conf_HTTPS_Cert           ; eg. "cert.pem"
lweb::#conf_HTTPS_Key            ; eg. "privkey.pem"
lweb::#conf_HTTPS_Key_Pass       ; eg. "Passw0rd"
lweb::#conf_max_HTTPS_clients    ; Max connected Clients to the HTTPS Server
lweb::#conf_HTTPS_Enable         ; It enable the https server (0 disabled and 1 enabled.)

Other Server Configuration:
lweb::#conf_defaultfile          ;Default file wen no file is selected(With extension!) e.g. "index.php"
lweb::#conf_basedir              ;Default directory e.g. "/srv/www/htdocs/"
lweb::#conf_error400             ;TBD:error400
lweb::#conf_max_clients          ;Max clients connected at the same time. (Watch memory limits!)
lweb::#conf_server_type          ;Currently no function.(e.g. HTTPS, HTTP/2)
lweb::#conf_cache_enable         ;It enable the cache mode (0 disabled and 1 enabled.) Currently with debugger unstable.

Functions

lweb::set_config(parameter.i=#conf_defaultfile, setting.s="index.html")

Setting must be a string.

Response is #True or #False.

lweb::get_config(parameter.i=#conf_defaultfile)

Responste is everytime a string.

Server start

lweb::start_server()

Response is #True or #False.

Different way to register a handler:

lweb::register_client_handler(Route.s, Callback.i, AppPrototype.i = #handler_proto_get, RouteType.i = #handler_sub)

Response is a JSONString!

AppPrototype parameter:

lweb::#handler_proto_universal      ;Works with HTTP POST and GET requests and takes optional a string.
lweb::#handler_proto_post           ;Works only with HTTP POST and needs a string.
lweb::#handler_proto_get            ;Works only with HTTP GET withouth a string.

RouteType parameter:

lweb::#handler_only         ;React only on a explicit Url (e.g. /rest/v1/test but not /rest/v1/test/sub)
lweb::#handler_sub          ;React on a full sub url. (e.g. /rest/v1/test and also /rest/v1/test/sub)
lweb::#handler_type         ;React on called file type (e.g. *.php = "php")

Response is a simple Stringmap: NewMap Response.s()

Following values must be set in a stringmap:

  • lweb::#cha_R_ResponseType = "ResponseType" ;Element ResponseType,Mimetype set e.g. lweb::mimetype("html").
  • lweb::#cha_R_ResponseContentType = "ResponseContentType" ;Element ResponseContentType, lweb::#response_string or lweb::#response_Memory
  • lweb::#cha_R_MemoryAdress = "MemoryAdress" ;Element MemoryAdress, convert to string Str(Adresse) converted back by Val(). After finished the work it will be freed!
  • lweb::#cha_R_MemorySize = "MemorySize" ;Element MemorySize, convert to string Str(Size) converted back by Val().
  • lweb::#cha_R_StringBase64 = "StringBase64" ;Element StringBase64, Base64 encoded string
  • lweb::#cha_R_http_head_status = "HeaderStatus" ;"200 OK", "300 Error", "500 Server Error" etc.

It's only allowed to response a base64 encoded string or a memoryblock.

Complete example:

Procedure.s Sample_Header(Map Header.s())
  Define *Text
  Define.s Encoded, ToSend, TBD
  NewMap Response.s()
  TBD="<div><div><h1>Header</h1></div><br/>"+#CRLF$
  ResetMap(Header())
  While NextMapElement(Header())
    TBD = TBD+"<div>"+MapKey(Header())+" : "+Header()+" </div><br/>"+#CRLF$
  Wend
  
  *Text = UTF8("<!DOCTYPE html><html><header><title>Alle Client Headers</title></header><body>"+TBD+"</body></html>")
  Encoded = Base64Encoder(*Text, MemorySize(*Text))
  Debug "Encoded: " + Encoded
  Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
  Response(lhs_web::#cha_R_StringBase64) = Encoded
  Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
  Response(lhs_web::#cha_R_http_head_status) = "200 OK"
  ToSend = lhs_web::MapToJSONString(Response())
  Debug "ToSend: " + ToSend
  ProcedureReturn ToSend
EndProcedure

lhs_web::register_client_handler("/server/show_client_headers", @Sample_Header(),lhs_web::#handler_proto_get, lhs_web::#handler_sub)

HTML mimetype of a file extension:

lweb::mimetype(file.s)

Response is a string.

Converts e.g. lweb::mimetype("html") to "text/html"

Convert a map to a JSONString. Interaction for example with a SpiderBasic app.

lweb::MapToJSONString(Map ConvertMap.s())

Response is a string.

Example:

  Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
  Response(lhs_web::#cha_R_StringBase64) = Encoded
  Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
  Response(lhs_web::#cha_R_http_head_status) = "200 OK"
  ToSend = lhs_web::MapToJSONString(Response())

The converted map would be possible to converted back by the main worker procedure (Client thread from lweb.pbi).

Verification if it is a valid IP Address (IPv6 and IPv4)

lweb::IsIPStringValid(Adress.s)

Example:

setting = "192.168.256.12"
If lweb::IsIPStringValid(setting)
    conf_binding = setting
Else
    ; failed
    conf_binding = "127.0.0.1"
EndIf

Validation will be failed because 256 is not valid.

Response is #True or #False.