Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpServer#tryWrite #529

Open
zhoujiaping opened this issue Aug 2, 2023 · 1 comment
Open

HttpServer#tryWrite #529

zhoujiaping opened this issue Aug 2, 2023 · 1 comment

Comments

@zhoujiaping
Copy link

HttpServer#tryWrite

// in SocketChannelImpl#write, it will change the buffer's position to it's limit.
// so the following if always get false.
ch.write(buffers, 0, buffers.length);
if (buffers[buffers.length - 1].hasRemaining()) {

My environment:
Leiningen 2.10.0 on Java 11.0.2 Java HotSpot(TM) 64-Bit Server VM
or
Leiningen 2.10.0 on Java 1.8.0-262 OpenJDK 64-Bit Server VM

#####project.clj

(defproject clojure-cook "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.11.1"]
                 [org.clojure/tools.trace "0.7.11"]
                 [org.clojure/data.json "2.4.0"]
                 [org.clojure/tools.logging "1.2.4"]
                 [org.slf4j/slf4j-api "2.0.7"]
                 [ch.qos.logback/logback-core "1.3.8"]
                 [ch.qos.logback/logback-classic "1.3.8"]
                 [celtuce "0.4.2"]
                 [http-kit "2.7.0"]
                 ]
  :jvm-opts ["-Dclojure.tools.logging.factory=clojure.tools.logging.impl/jul-factory"]
  :repl-options {:init-ns clojure-cook.core })

;-Dclojure.tools.logging.factory=clojure.tools.logging.impl/jul-factory

#####http_server_demo.clj

(ns clojure-cook.http-server-demo
  (:require [org.httpkit.server :as http-server]
            [clojure.pprint :refer [pprint]]
            [clojure.string :as string])
  (:import (java.net URLDecoder)
           (java.nio ByteBuffer)))



(http-server/run-server
  (fn [{body :body :as req}]
    (pprint req)
    (pprint (:query-string req))                           
    (when (some? body) (pprint (slurp (:body req))))
    {:status  200
     :body    (doto (ByteBuffer/allocate 10) (.put (byte 65)) (.put (byte 66)) (.rewind))
     :headers {
               "Content-Type" "application/text; charset=utf-8"}})
  {:port 8080})                                             

#####http_client_demo.clj

(ns clojure-cook.http-client-demo
  (:require [org.httpkit.client :as http-cli]
            [clojure.pprint :refer [pprint]]
            [clojure.string]
            [clojure.data.json :as json]))
;(require '[org.httpkit.client :as http-cli])
;(require '[clojure.pprint :refer [pprint]])
;(require '[clojure.string])
;(require '[clojure.data.json :as json])

;; 
(http-cli/get "http://localhost:8080" (fn [resp] (pprint resp)))
@ptaoussanis
Copy link
Member

Hi @ zhoujiaping, to make this issue easier for contributors to understand - can you please clarify what the intention of your issue is?

Are you reporting a bug?
If so: can you please be specific about what what output you're expecting, and what output you're actually seeing?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants