{"id":1251,"date":"2016-02-14T11:30:21","date_gmt":"2016-02-14T02:30:21","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=1251"},"modified":"2016-02-14T00:36:41","modified_gmt":"2016-02-13T15:36:41","slug":"set-http-header-with-socket-io-client","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2016\/02\/set-http-header-with-socket-io-client\/","title":{"rendered":"socket.io-client \u3067 HTTP \u30d8\u30c3\u30c0\u30fc\u3092\u8a2d\u5b9a\u3059\u308b"},"content":{"rendered":"
Socket.IO<\/a> \u3092\u5229\u7528\u3059\u308b\u969b\u306b, HTTP \u30d8\u30c3\u30c0\u30fc\u306b\u8a8d\u8a3c\u30c8\u30fc\u30af\u30f3\u3084 Cookie \u3092\u8a2d\u5b9a\u3057\u305f\u3044\u3068\u3044\u3046\u30b1\u30fc\u30b9\u304c\u3042\u308a\u307e\u3059. \u5f93\u6765 HTTP \u30d8\u30c3\u30c0\u30fc\u3092 Socket.IO \u3067\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306f\u96e3\u3057\u3044\u3068\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u304c, socket.io-client<\/a> 1.4 \u4ee5\u964d\u3067\u306f <\/p>\n \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067 Socket.IO \u306e\u63a5\u7d9a\u3092\u884c\u3046\u969b\u306b\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306b \u30b5\u30fc\u30d0\u30fc\u5074\u3067\u306f \u4f8b\u3048\u3070, extraHeaders<\/code> \u3092\u7528\u3044\u3066\u8a2d\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059.<\/p>\n
\u4f7f\u3044\u65b9<\/h2>\n
extraHeaders<\/code> \u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067, \u30ea\u30af\u30a8\u30b9\u30c8\u306b\u8ffd\u52a0\u306e HTTP \u30d8\u30c3\u30c0\u30fc\u3092\u8a2d\u5b9a\u51fa\u6765\u307e\u3059.<\/p>\n
var socket = require('socket.io-client')('http:\/\/localhost', {\r\n extraHeaders: {\r\n Authorization: \"Bearer authorization_token_here\"\r\n }\r\n});\r\n<\/pre>\n
socket.request.headers<\/code> \u3067\u30ea\u30af\u30a8\u30b9\u30c8\u306e HTTP \u30d8\u30c3\u30c0\u30fc\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059.<\/p>\n
extraHeaders \u306b\u3064\u3044\u3066<\/h2>\n
extraHeaders<\/code> \u306f socket.io-client 1.4 \u304b\u3089\u5229\u7528\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059.
extraHeaders<\/code> \u306f socket.io-client \u306e\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3092\u62c5\u3046 engine-io.client \u306e\u30d0\u30fc\u30b8\u30e7\u30f3 1.6 \u3067\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f<\/a>.<\/p>\n
\u305d\u306e\u4ed6<\/h2>\n
extraHeaders<\/code> \u3067\u3000
Authorization<\/code> \u30d8\u30c3\u30c0\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067, \u7c21\u5358\u306b BASIC \u8a8d\u8a3c\u306b\u5bfe\u5fdc\u3055\u305b\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059. \u7c21\u6613\u306e\u8a8d\u8a3c\u3068\u3057\u3066 BASIC \u8a8d\u8a3c\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306f\u4fbf\u5229\u3067\u3059.<\/p>\n