Giter VIP home page Giter VIP logo

http's People

Contributors

elimisteve avatar jakski avatar khachig avatar pepe avatar swlkr 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

Watchers

 avatar  avatar  avatar

http's Issues

SSL Connection Error / Issues with PR 12

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?

Multi-value header support

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))))

Unable to send body with null

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.

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.