Giter Club home page Giter Club logo

circlet's People

Contributors

ahungry avatar bakpakin avatar pepe avatar saikyun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

circlet's Issues

multiple header values

I think, but am not certain, that some headers like 'Set Cookie' don't work so well comma separated. I think to work around this is may be nice to support arrays/tuples as header values indicating multiple values.

e.g.

:headers {"Set Cookie" [v1 v2 v3]}

I have implemented this in poolparty.

Default the network interface to `localhost` otherwise specify it

Currently circlet/server takes only a port parameter and binds to all available interfaces behind the scenes. The caller has no control over what interface(s) to bind to. I believe that this is not a good design and causes certain security risks. Any network server should bind to localhost only as a default and make the interface explicitly controllable if desired otherwise.

I propose a modification with the following semantics:

(server 8000)                 ==> Circlet server listening on [localhost:8000] ...

(server 8000 "localhost")     ==> Circlet server listening on [localhost:8000] ...

(server 8000 "192.168.1.130") ==> Circlet server listening on [192.168.1.130:8000] ...

(server 8000 "*")             ==> Circlet server listening on [*:8000] ... (all interfaces)

Fortunately the necessary changes are minimal and can be done on high level in circlet_lib.janet:

diff --git a/circlet_lib.janet b/circlet_lib.janet
index 52b3d0e..23fe61d 100644
--- a/circlet_lib.janet
+++ b/circlet_lib.janet
@@ -35,13 +35,18 @@
 
 (defn server 
   "Creates a simple http server"
-  [port handler]
+  [handler port &opt ip-address]
   (def mgr (manager))
   (def mw (middleware handler))
+  (default ip-address "localhost")
+  (var interface nil)
+  (if (peg/match "*" ip-address)
+    (set interface (string port))
+    (set interface (string/format "%s:%d" ip-address port)))
   (defn evloop []
-    (print "Circlet server listening on port " port "...")
+    (print (string/format "Circlet server listening on [%s:%d] ..." ip-address port))
     (var req (yield nil))
     (while true
       (set req (yield (mw req)))))
-  (bind-http mgr (string port) evloop)
+  (bind-http mgr interface evloop)
   (while true (poll mgr 2000)))

Using os module functions causes root fiber to panic

Hi, I'm trying to write a little web app on circlet and I'm trying to spawn some processes like this one when I receive a request to certain endpoint.

(defn getls
  "gets ls from bin dir" []
  (def procc (os/spawn ["ls"] :p {:in :pipe :out :pipe :err :pipe}))
  (pp :waiting_for_proc)
  (pp (:wait procc))
  [(:read (procc :out) :all)
   (:read (procc :err) :all)])

the first time I get the request nothing happens, but when I try to request again I got an error that says:
current fiber is already waiting for event

could you explain me why this happens? is this a bug or maybe I'm not familiar enough with how things work in Janet or with Circlet

Serving a binary file doesn't work as expected

I think I should be able to just set the content-type to the appropriate value and serve a file by writing the slurped file to the body of the response, and this indeed works for ascii files. But not for binary files like pngs.

When I run below code and visit the page, the browser says the file is broken and cannot be displayed.
Tried different pngs and different image formats. The response's body seems to contain only the first 10 Bytes of the image I slurp. That slice coincides with a byte of 0x00 in the file. The content type and length are set to their correct values.

(import circlet)

(defn myserver [req]
  (def data (slurp (string (os/cwd) "/test.png")))
  {:status 200
   :headers {"Content-Type" "image/png"}
   :body data})

(circlet/server myserver 8000)

excerpt from test.png:
8950 4e47 0d0a 1a0a 0000 000d 4948 4452 0000 03c0 0000 03cd ...
sole content of received body:
8950 4e47 0d0a 1a0a 0d0a

Problem building with new mongoose

I wanted to try wrapping the websocket stuff, so I looked at a mongoose example: https://github.com/cesanta/mongoose/tree/master/examples/websocket-server

It needs latest mongoose though, so I tried jpm run update-mongoose. However, now jpm build is unable to build mongoose.
It appears as though some required files aren't included (e.g. time.h and limit.h). I could resolve this by hard coding includes for these, but I don't need to do that if I compile mongoose manually using gcc (without jpm build that is), so I'm unsure about what's going on.

I'm on Ubuntu, Janet 1.17.1-b799223e and jpm c2be9143201154c2b068f954474f1e0983f81189.

Here's the errors I get after running update-mongoose then jpm build. I understand that I get circlet-errors, it's the ones relating to mongoose.h I'm confused about: https://pastebin.com/6fzA15w6

Cook?

I'm using Janet 1.0.0-dev-232ea22 from janet-lang-git on the AUR.

Unfortunately build won't run because Janet doesn't know where cook is.

... Any idea where I can find this dependency?

How would you use this in a different app?

Lets say that I want to write an API in Janet/C.

I have janet and jpm. I built circlet and run the test. I now have a build/circlet.so file - would that (and the appropriate janet files) be all I need to pull into my own codebase? Where I could then initialize a server similar to the sample in readme? just an (import circlet)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.