atomic web server threads

Share your advanced PureBasic knowledge/code with the community.
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

PBJim wrote: Mon Apr 15, 2024 6:55 am Thanks very much Idle, there is the below code which won't compile, as it's attemping to put -1 into an unsigned .a

Code: Select all

  Structure ST
    a.a[256] 
  EndStructure  
  Static skiptable.ST 

[...]
    For i = 0 To 255
      Skiptable\a[i] = -1;
Line 520: Overflow error a 'ascii' (.a) value must be between 0 and 255
Thanks, replace it with 255, I'm still using pb 6.10 b6
I expected it to cast to unsigned
PBJim
Enthusiast
Enthusiast
Posts: 294
Joined: Fri Jan 19, 2024 11:56 pm

Re: atomic web server threads

Post by PBJim »

idle wrote: Mon Apr 15, 2024 8:37 am Thanks, replace it with 255, I'm still using pb 6.10 b6
Thanks, yes that's fixed it, it's working well.
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

PBJim wrote: Mon Apr 15, 2024 9:26 am
idle wrote: Mon Apr 15, 2024 8:37 am Thanks, replace it with 255, I'm still using pb 6.10 b6
Thanks, yes that's fixed it, it's working well.
Thanks for pointing it out.
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

tested on ubuntu 22.04, you might need to change ports to 8080 and 8081 to test.
also check that index.html is lower case
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: atomic web server threads

Post by skinkairewalker »

tomorrow i’ll test on mac
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: atomic web server threads

Post by Caronte3D »

I'm testing the Get/Post now and after some minor tweaks, it works nice :D
but...
Is there already implemented a way to use persistent variables by session/client?

I mean... by example:
I use Post to get the name of user then I use that variable name on next page refreshes (or another ones) without Post
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

Caronte3D wrote: Wed Apr 17, 2024 10:19 am I'm testing the Get/Post now and after some minor tweaks, it works nice :D
but...
Is there already implemented a way to use persistent variables by session/client?

I mean... by example:
I use Post to get the name of user then I use that variable name on next page refreshes (or another ones) without Post
The get and post callbacks are a bit half baked at the moment as in they don't allow you to modify anything, they just let you read a request and while you have a map of parameters you also really need the ability to modify header fields so you can set cookies and such. I haven't really given it much thought yet. I do plan on adding a map of header fields which will also make the internal processing a bit easier and then you could set a cookie or add header fields.

This might be a useful reference
https://developer.mozilla.org/en-US/doc ... TP/Cookies
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: atomic web server threads

Post by Caronte3D »

Ok, ok...
I wasn't expecting a mature server like the big ones, but some things are essential.
I will wait until you advance more on this nice project, I would like to help you, but my web programing skills are near zero :?
Thanks again! :wink:
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

Caronte3D wrote: Wed Apr 17, 2024 2:28 pm Ok, ok...
I wasn't expecting a mature server like the big ones, but some things are essential.
I will wait until you advance more on this nice project, I would like to help you, but my web programing skills are near zero :?
Thanks again! :wink:
It won't be hard to add session state but it still needs a bit more thought.

I've been adding compression based on request and mime type which is a no brainer no point compressing something that's already compressed and fixed up some minor bugs.

Incidentally the server is now getting a B grade on https://tools.pingdom.com/ it's quite useful for testing relative load times from different locations.
http://atomicwebserver.com/index.html

Version 3.0.8b2
Added deflate
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: atomic web server threads

Post by Caronte3D »

Nice! 8)
I just noticed you have a PayPal button on the atomic server page, so I'm donating a little to pay you for some coffees. :wink:
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: atomic web server threads

Post by Fred »

Great website and project :D
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

Caronte3D wrote: Thu Apr 18, 2024 8:10 am Nice! 8)
I just noticed you have a PayPal button on the atomic server page, so I'm donating a little to pay you for some coffees. :wink:
Thanks, there's still a lot to do but its a good start, I will look into adding the session stuff next.
Fred wrote: Thu Apr 18, 2024 9:23 am Great website and project :D
Thanks, there's sill a bit to do, like TLS and the virtual file system / cache in memory keypair store but they will be optional plugins and maybe it will inspire you to add a libreSSL build to the pb libs once you see it all working.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: atomic web server threads

Post by sec »

idle wrote: Thu Apr 18, 2024 1:13 pm
Caronte3D wrote: Thu Apr 18, 2024 8:10 am Nice! 8)
I just noticed you have a PayPal button on the atomic server page, so I'm donating a little to pay you for some coffees. :wink:
Thanks, there's still a lot to do but its a good start, I will look into adding the session stuff next.
Fred wrote: Thu Apr 18, 2024 9:23 am Great website and project :D
Thanks, there's sill a bit to do, like TLS and the virtual file system / cache in memory keypair store but they will be optional plugins and maybe it will inspire you to add a libreSSL build to the pb libs once you see it all working.
Add load balance, reverse proxy … we will get rid nginx … :p
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

I just don't know how I'll do it yet
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: atomic web server threads

Post by idle »

v3.0.8b3

Added header fields and cookies
Request header fields are read via map *request\RequestHeaders()
you can also add additional client Response headers via Atomic_Server_SetResponceHeader(*request.Atomic_Server_Request,key.s,value.s)

Cookies are extracted and mapped to *client\Cookies()
you can set cookies in a callback via
Atomic_Server_SetCookie(*request.Atomic_Server_Request,Cookie.s,value.s)

the cookies are available in callbacks to GET POST URIHandlers and Preprocessor functions

Code: Select all

Procedure URIfoo(*request.Atomic_Server_Request)
  
  Protected  *Atomic_Server.Atomic_Server = *request\serverid 
  Protected  *client.Atomic_Server_Client = *request\clientID 
  Protected  content.s,session.s,setsession.s   
  Protected *data
  
  If FindMapElement(*client\Cookies(),"sessionID")  
    session = *client\Cookies()
  Else   
    setsession = Str(Random($FFFFFFFF)) + "; " + "Max-Age=" + "60"  
    Atomic_Server_SetCookie(*request,"sessionID",setsession)
  EndIf  
  
  Debug *request\Request 
  
   content.s = "<!DOCTYPE html>" + #CRLF$
   content + "<html><head>" + #CRLF$
   content + "<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Noto Sans&effect=fire'>" + #CRLF$
   content + "<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Noto Color Emoji'>" + #CRLF$
   content + "<meta charset='utf-8' />" + #CRLF$
   content + "<title>" + *Atomic_Server\Title + "</title>" + #CRLF$
   content + "<style> body { background-color: #6600ff; margin: 10%;} h1 { font-family: 'Noto Sans', sans-serif; color: white;  text-align: center; } " + #CRLF$
   content + "p { font-family: 'Noto Sans', sans-serif; font-size: 18px;  text-align: center; color: white;} " + #CRLF$ 
   content + "h2 { font-family: 'Noto Color Emoji'; text-align: center; } " + #CRLF$ 
   content + "label { font-family: 'Noto Sans', sans-serif; font-size: 30px;  text-align: left; color: white;} " + #CRLF$ 
   content +  "input[type=text], Select { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } " + #CRLF$  
   content +  "input[type=submit] { width: 100%; background-color: #0099cc; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; } </style>"  + #CRLF$
   content + "</head><body><h1 class='font-effect-fire' style='text-align:center';>" + *Atomic_Server\Title + "</h1>"+ #CRLF$
   content + "<h2 style='text-align:center';>" + Atomic_Server_Chr($2622) + "</h2>"
   ForEach *request\parameters() 
    content + "<p>" + MapKey(*request\parameters()) + "=" + *request\parameters() +"</p>" 
   Next 
   If session <> ""
     content + "<p>" + "sessionID =" + session + "</p>"  
   EndIf 
   
   content + "<body></html>"
    
  *data = UTF8(content)
  
  *request\ContentType = "text/html" ;Set the contentType
  
  ProcedureReturn *data  
  
EndProcedure 

Post Reply