I'm writing an application in which the server can quickly rule out a request based on it's headers. When this happens the server will send back a 4xx response. If the client is sending a large body in a POST, it will cause a "java.net.ScoketException: Broken pipe" on the client.
The issue appears to be that client expects to fully send it's request before accepting a response.
Here is a simple test that exhibits the problem:
(ns http-test.core
(:require [clj-http.client :as client]
[org.httpkit.server :refer [run-server]]))
;; Server
(defn app [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body "hello HTTP!"})
(run-server app {:port 8080})
;; Client
(def s (slurp "big-file.txt"))
(client/post "http://localhost:9091/run" {:body s})
(defproject http-test "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[clj-http "2.0.0"]
[http-kit "2.1.18"]
])
big-file.txt is 12 mb. A 112kb file doesn't cause cause the problem.
I'm writing an application in which the server can quickly rule out a request based on it's headers. When this happens the server will send back a 4xx response. If the client is sending a large body in a POST, it will cause a "java.net.ScoketException: Broken pipe" on the client.
The issue appears to be that client expects to fully send it's request before accepting a response.
Here is a simple test that exhibits the problem:
big-file.txt is 12 mb. A 112kb file doesn't cause cause the problem.