Permalink
Browse files

remove unused file; remove async-resposne; update history

  • Loading branch information...
1 parent ca6e6c9 commit 4a1ef09a05e79e6ed0a0b0a3b27231a76c0b6cf6 @shenfeng shenfeng committed Mar 28, 2013
View
@@ -8,7 +8,7 @@ Current [semantic](http://semver.org/) version: `[http-kit "2.0.0-RC4"]`.
### Hack locally
-Hacker friendly: only ~3k lines of code (including java), clean and tidy.
+Hacker friendly: Written from ground-up, only ~3k lines of code (including java), clean and tidy.
```sh
# modify as you want, unit tests back you up
View
@@ -1,162 +0,0 @@
-# Http Kit
-
-高性能HTTP Server (Ring adapter), HTTP Client。使你的Clojure Web 程序拥有类似Nginx的性能
-
-## 特点
-
-* 从头写,jar文件仅80k => 代码少,bug少
-* 为高性能服务器打造
-
-### HTTP Server
-
-* **性能** 第三方独立测评结果: [clojure-web-server-benchmarks](https://github.com/ptaoussanis/clojure-web-server-benchmarks)
-* 并发支持:仅需几K内存来保持一个HTTP连接,空闲连接几乎不影响latency。
-* 支持Async [HTTP长连](http://en.wikipedia.org/wiki/Comet_(programming),实时push 更新给客户端
-* 支持 [WebSocket](http://tools.ietf.org/html/rfc6455),实时双向通讯
-
-### HTTP Client
-
-* 同步的感觉,异步的API(promise),需要结果,加@就行
-* 每个请求可独立设置超时: *服务器程序,超时很重要*
-* keep-alive: *如果对方服务器支持。为性能,不遗余力*
-* 线程安全
-
-http-kit使用了和Nginx相似的并发模型,具有和Nginx相似的并发处理能力。
-
-## HTTP Server 用法
-
-### 添加依赖
-
-```clj
-;; 在project.clj中添加依赖
-[http-kit "2.0-rc1"]
-[compojure "1.1.1"]
-
-;;; 引入依赖
-(:use org.httpkit.http.server ;; 引入 http-kit Server
- compojure.core) ;; Router, 方便定义handler
-```
-
-### Hello world
-
-```clj
-;; 普通Clojure函数:handler。 参数request:map,包含HTTP Request的信息, 如form参数,上传的文件,URL等。
-;; 打印 (println request), 以查看
-(defn web-handler [request]
- ;; 返回符合ring规范的response map
- {:status 200
- :headers {"Content-Type" "text/html; charset=utf8"}
- ;; body 可以是字符串,文件,InputStream,或者Sequence
- :body "hello word from http-kit"})
-
-;; 启动http server,监听在8080端口。 run-server返回一个函数,用于停止server
-;; 浏览器访问 http://127.0.0.1:8080/,将看到 hello word from http-kit
-(run-server handler {:port 8080})
-```
-
-### 异步接口,http长连,long polling
-
-一个接口:`async-response`
-
-**示例**
-
-```clj
-;; 普通Clojure函数。 参数request:map,包含HTTP Request的信息
-(defn async-handler [request]
- ;; 通过async-response宏实现HTTP长连
- (async-response respond! ;; respond!是一个函数,可以被保存下来,在任意时刻,在任意线程调用,用于返回结果给浏览器
- (future
- ;; 可以返回字符串,文件,InputStream,或者Sequence。并且可以加上HTTP status, headers等
- (respond! "异步调用"))))
-
-(defroutes web-handler ;;定义router: URL dispatch 规则
- (GET "/" [] "This is Index Page")
- (GET "/async" [] async-handler))
-
-(run-server web-handler {:port 8080})
-
-```
-用HTTP长连实现的聊天室例子,在[examples/polling目录](https://github.com/shenfeng/http-kit/tree/master/examples/polling)
-
-
-### Websocket,实时双向通信
-
-* `if-ws-request` 或者 `when-ws-request`: 判断是否是Websocket请求,并开始处理
-* `on-mesg`: 收到来自客户端发来的文本消息
-* `send-mesg`: 主动给客户端发送文本消息
-* `on-close`: 连接关闭(服务器主动,或者客户端主动)
-* `close-conn`: 服务器主动关闭连接
-
-**示例**
-
-```clj
-;; 普通Clojure函数。
-(defn ws-handler [request]
- ;; 通过if-ws-request 支持websocket, 也可以用when-ws-request
- (if-ws-request request
- conn ;; conn表示websocket连接,可以被保存下来,它是线程安全的
- (do
- ;; websocket连接建立成功
- (on-mesg conn (fn [mesg] ;; 接收到来自客户端发来的文本消息 mesg
- ))
- (on-close conn (fn [] ;; websocket连接已经关闭(客户端关闭,服务端关闭)
- ;; 可用于善后处理
- ))
- ;; 服务器端向客户端发送文本消息, 可在任意线程调用
- (send-mesg conn "A message from server by websocket")
- (close-conn conn)) ;; 服务器端主动关闭连接
- ;; 不是websocket请求
- "No a websocket request?"))
-
-(defroutes web-handler
- (GET "/" [] "This is Index Page")
- (GET "/ws" [] ws-handler))
-
-(run-server web-handler {:port 8080})
-```
-用WebSocket实现的聊天室, 在[examples/websocket目录](https://github.com/shenfeng/http-kit/tree/master/examples/websocket)
-
-## HTTP Client 用法
-
-```clj
-(:require [org.httpkit.client :as http])
-; 包括 `http/get`, `http/post`, `http/put` `http/delete` `http/put`
-```
-
-```clj
-
-;; 异步调用,返回的promise,忽略结果
-(http/get "http://host.com/path")
-
-;; 异步调用,异步处理
-(let [options {:timeout 200 ; ms
- :basic-auth ["user" "pass"]
- :query-params {:param "value"}
- :user-agent "User-Agent-string"
- :headers {"X-Header" "Value"}}]
- (http/get "http://host.com/path" options
- (fn [{:keys [status headers body error]}]
- (if error
- (println "Failed, exception is " error)
- (println "Async HTTP GET: " status)))))
-
-;; 同步调用
-(let [{:keys [status headers body error] :as resp} @(http/get "http://host.com/path")]
- (if error
- (println "Failed, exception: " error)
- (println "HTTP GET success: " status)))
-
-;; 并发调用,同步处理
-(let [resp1 (http/get "http://host.com/path1")
- resp2 (http/get "http://host.com/path2")]
- (println "Response 1's status " {:status @resp1})
- (println "Response 2's status " {:status @resp2}))
-
-;; Form提交
-(let [options {:form-parmas {:name "http-kit" :features ["async" "client" "server"]}}
- {:keys [status error]} @(http/post "http://host.com/path1" options)]
- (if error
- (println "Failed, exception is " error)
- (println "Async HTTP POST: " status)))
-
-```
View
@@ -47,3 +47,9 @@ HTTP server:
### 2.0-rc2 (2013/2/9)
1. fix a possible CPU 100% usage
+
+### 2.0-0 (2013/3/28)
+ 1. Unify WebSocket and HTTP long polling/streaming with Channel protocol and with-channel (API breaks with the RC)
+ 2. WebSocket support sending and receiving binary frame
+ 3. Support HTTP streaming
+ 4. Fix few issues with WebSocket
View
@@ -1,153 +0,0 @@
-;; 在project.clj中添加依赖
-[me.shenfeng/http-kit "1.2"]
-[compojure "1.1.1"]
-
-;;; 引入依赖
-(:use me.shenfeng.http.server ;; 引入 http-kit Server
- compojure.core) ;; Router, 方便定义handler
-
-
-;; 普通Clojure函数:handler。 参数request:map,包含HTTP Request的信息, 如form参数,上传的文件,URL等。
-;; 打印 (println request), 以查看
-(defn web-handler [request]
- ;; 返回符合ring规范的response map
- {:status 200
- :headers {"Content-Type" "text/html; charset=utf8"}
- ;; body 可以是字符串,文件,InputStream,或者Sequence
- :body "hello word from http-kit"})
-
-;; 启动http server,监听在8080端口。 run-server返回一个函数,用于停止server
-;; 浏览器访问 http://127.0.0.1:8080/,将看到 hello word from http-kit
-(run-server handler {:port 8080})
-
-
-
-;; 普通Clojure函数。 参数request:map,包含HTTP Request的信息
-(defn async-handler [request]
- ;; 通过async-response宏实现HTTP长连
- (async-response respond! ;; respond!是一个函数,可以被保存下来,在任意时刻,在任意线程调用,用于返回结果给浏览器
- (future
- ;; 可以返回字符串,文件,InputStream,或者Sequence。并且可以加上HTTP status, headers等
- (respond! "异步调用"))))
-
-(defroutes web-handler ;;定义router: URL dispatch 规则
- (GET "/" [] "This is Index Page")
- (GET "/async" [] async-handler))
-
-(run-server web-handler {:port 8080})
-
-;; 普通Clojure函数。
-(defn ws-handler [request]
- ;; 通过if-ws-request 支持websocket, 也可以用when-ws-request
- (if-ws-request request
- conn ;; conn表示websocket连接,可以被保存下来,它是线程安全的
- (do
- ;; websocket连接建立成功
- (on-mesg conn (fn [mesg] ;; 接收到来自客户端发来的文本消息 mesg
- ))
- (on-close conn (fn [] ;; websocket连接已经关闭(客户端关闭,服务端关闭)
- ;; 可用于善后处理
- ))
- ;; 服务器端向客户端发送文本消息, 可在任意线程调用
- (send-mesg conn "A message from server by websocket")
- (close-conn conn)) ;; 服务器端主动关闭连接
- ;; 不是websocket请求
- "No a websocket request?"))
-
-(defroutes web-handler
- (GET "/" [] "This is Index Page")
- (GET "/ws" [] ws-handler))
-
-(run-server web-handler {:port 8080})
-
-(:require [me.shenfeng.http.client :as http])
-
-;; 异步调用,忽略返回的promise
-(http/get "http://host.com/path")
-
-;; 异步调用,异步处理
-(http/get "http://host.com/path" {:keys [status headers body] :as resp}
- (if status
- (println "Async HTTP Get: " status)
- (println "Failed, exception is " resp)))
-
-;; 同步调用
-(let [{:keys [status headers body] :as resp} @(http/get "http://host.com/path")]
- (if status
- (println "HTTP Get success: " status)
- (println "Failed, exception: " resp)))
-
-;; 异步调用,Timeout 200ms, Basic Auth user@pass, 指定User-Agent
-(let [options {:timeout 200
- :basic-auth ["user" "pass"]
- :headers {"User-Agent" "User-Agent-string"}}]
- (http/get "http://host.com/path" options {:keys [status headers body] :as resp}
- (if status
- (println "Async HTTP Get: " status)
- (println "Failed, exception: " resp))))
-
-(def post-options {:form-params {:params1 "value" :params2 ["v1" "v2"]}
- :timeout 200 ;; timeout 200ms
- :headers {"Key" "Value"}})
-
-;;; 异步调用,忽略返回的promise
-(http/post "http://host.com/path" post-options)
-
-;;; 异步调用,异步处理
-(http/post "http://host.com/path" post-options {:keys [status headers body] :as resp}
- (if status
- (println "Async HTTP Post: " status)
- (println "Failed, exception: " resp)))
-
-;;; 同步调用
-(let [{:keys [status headers body] :as resp} @(http/post "http://host.com/path")]
- (if status
- (println "Sync HTTP Post: " status)
- (println "Failed, exception: " resp)))
-
-
-;;; ----------------------------------------
-
-
-;; Asynchronous,return a promise
-(http/get "http://host.com/path")
-
-;; Asynchronous
-(http/get "http://host.com/path" {:keys [status headers body] :as resp}
- (if status
- (println "Async HTTP Get: " status)
- (println "Failed, exception is " resp)))
-
-;; Synchronous
-(let [{:keys [status headers body] :as resp} @(http/get "http://host.com/path")]
- (if status
- (println "HTTP Get success: " status)
- (println "Failed, exception: " resp)))
-
-;; Asynchronous: Timeout 200ms, Basic Auth user@pass, Customise User-Agent
-(let [options {:timeout 200
- :basic-auth ["user" "pass"]
- :headers {"User-Agent" "User-Agent-string"}}]
- (http/get "http://host.com/path" options {:keys [status headers body] :as resp}
- (if status
- (println "Async HTTP Get: " status)
- (println "Failed, exception: " resp))))
-
-(def post-options {:form-params {:params1 "value" :params2 ["v1" "v2"]}
- :timeout 200 ;; timeout 200ms
- :headers {"Key" "Value"}})
-
-;; Asynchronous,return a promise
-(http/post "http://host.com/path" post-options)
-
-;; Asynchronous
-(http/post "http://host.com/path" post-options {:keys [status headers body] :as resp}
- (if status ;; when response is ready
- (println "Async HTTP Post: " status)
- (println "Failed, exception: " resp)))
-
-;;; Synchronous
-(let [{:keys [status headers body] :as resp} @(http/post "http://host.com/path")]
- (if status
- (println "Sync HTTP Post: " status)
- (println "Failed, exception: " resp)))
@@ -131,9 +131,3 @@
{:status 400 :body "Bad Sec-WebSocket-Key header"})
(do ~@body
{:body ~ch-name}))))
-
-(defmacro async-response "DEPRECATED"
- [request callback-name & body]
- `(with-channel ~request ch#
- (let [~callback-name (fn [data#] (send! ch# data# true))]
- ~@body)))
@@ -11,8 +11,8 @@ import (
)
const (
- origin = "http://localhost:9899/"
- wsurl = "ws://localhost:9899/test"
+ origin = "http://localhost:9090/"
+ wsurl = "ws://localhost:9090/ws"
)
var concurrency = flag.Int("c", 100, "concurrency")
File renamed without changes.
Oops, something went wrong.

0 comments on commit 4a1ef09

Please sign in to comment.