joy-framework / http Goto Github PK
View Code? Open in Web Editor NEWA janet http client library
License: MIT License
A janet http client library
License: MIT License
Hello,
Prior to #12 this code worked:
(import http)
(pp (http/get "https://example.com"))
Post PR #12 it instead errors with "SSL Connection Error"
I believe that this (from #12)
Janet janet_port = janet_table_get(options, janet_ckeywordv("port"));
long port = 80;
if (janet_checktype(janet_port, JANET_NUMBER)) {
port = (long)janet_unwrap_integer(janet_port);
}
was intended to supply a default port (80) if no port was specified, which it does, but in so doing it makes port a required option for all non-http requests.
Prior to #12 we could already specify a port, like so:
(import http)
(pp (http/get "http://localhost:8080"))
Which to me feels like the more natural place to do so.
Could we return to curl determining the default port if not specified?
jpm install http
or similar feels like it should work ๐
Sometimes, a response can have multiple headers sharing the same key (e.g. Set-Cookie
).
The current implementation squashes everything through (apply table)
, thus discarding every header but the last.
I've been trying to work on a patch since I need multi-value header support, but not only that'll completely break the current format, the result I produced is... uncertain imho.
Would you mind giving some tips / opinions on this? Thanks
(defn parse-headers [response]
(let [str (get response :headers)]
(->> (string/split "\r\n" str)
(filter |(string/find ":" $))
- (mapcat |(string/split ":" $ 0 2))
- (map string/trim)
- (apply table)
+ (map |(map string/trim (string/split ":" $ 0 2)))
+ (reduce |(let [key (first $1) value (last $1)]
+ (if-let [entry (get $ key)]
+ (set ($ key) [;entry value])
+ (put $ key [value]))
+ $) @{})
(freeze))))
Sending request with null in body isn't currently possible. Let's create example file with null byte inside and start listening for connection with netcat:
$ printf 'visible message\0invisible message' > text
$ nc -lp 8080
Now from second terminal http
will send POST request with this file as a payload:
repl:1:> (import http)
...
repl:2:> (def payload (slurp "text"))
@"visible message\0invisible message"
repl:3:> (http/post "http://127.0.0.1:8080" payload)
...
In first terminal only first message is received:
$ nc -lp 8080
POST / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: janet http client
Accept: */*
Content-Length: 15
Content-Type: application/x-www-form-urlencoded
visible message
This is the most problematic when sending binary data like images. PNG and JPEG usually contain null bytes which truncate message and make payload invalid.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.