Skip to content

http does not accept responses without a Reason Phrase #294

Description

@birchb1024

Some HTTP servers (like mine) do not bother to respond with 200 OK, just 200 (trailing space)

When doing a POST with spork/http like this

(defn table-to-form-encoded [data]
  (string/join (map
                 (fn [p]
                   (let 
                    [k (p 0)
                     v (p 1)
                     fmt (cond  (integer? v) "d" (number? v)  "g" (string? v)  "s" true "m")]
                     (string/format (string "%s=%" fmt) k v))) 
                 (pairs data)) "&"))

(defn make-post-request [url data]
  (let [body (table-to-form-encoded data) headers {"Content-Type" "application/x-www-form-urlencoded"}]
    (printf "%m" ['make-post-request headers body])
    (let [response (http/request "POST" url :headers headers :body body)]
      (printf "25 %m" response)
      (print "Status Code: " (response :status))
      (print "Response Body: " (response :body)))))

The POST is successful in that it's accepted by the server, but spork/request just throws an error .

However the RFC says that the Reason Phrase is optional. Refer StackOverflow

Please consider changing (some :printable) to (any :printable) in http.janet` :

(def- http-grammar                                                                        
  ~{:request-status (* :method :ws :path :ws "HTTP/1." :d :any-ws :rn)
    :response-status (* "HTTP/1." :d :ws (/ ':d+ ,scan-number)
                        :ws '(some :printable) :rn)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions