天天看點

netty-http-response

在response中可以設定cookie,可以傳回非html頁面,如jpg或zip等。

response的eader中說明了浏覽器需要記住哪些cookie。見下圖。

netty-http-response

io.netty.handler.codec.http.defaultcookie.defaultcookie(string name, string value)

建立一個cookie。

httpheaders io.netty.handler.codec.http.httpmessage.headers()

傳回http消息的頭部。

httpheaders io.netty.handler.codec.http.httpheaders.set(charsequence name, object value)

設定頭部的鍵值對。

charsequence io.netty.handler.codec.http.httpheaders.names.set_cookie

字元串常量,内容為"set-cookie"。

string io.netty.handler.codec.http.clientcookieencoder.encode(cookie cookie)

cookie結構體編碼為字元串,以便放入httpresponse的頭部。

sample

1.設定頭部

response.headers().set(content_type, "mage/jpeg; charset=utf-8");//說明content為圖檔

2.寫入二進制資料

bytebuf io.netty.buffer.bytebuf.writebytes(bytebuf src)

先将byte轉為bytebuf,再通過此方法把二進制資料寫入。