UNPKG

waffle

Version:

シンプルなWEBアプリケーションフレームワークです。(ALL YOUR NODE ARE BELONG TO US)

60 lines (54 loc) 1.57 kB
/* * Copyright 2012 Katsunori Koyanagi * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ /** * @overview リクエストボディを文字列として取得し、コンテキストに設定するフィルタです。 */ "use strict"; var ignoreMethods = { "GET" : null, "HEAD" : null }; /** * リクエストボディを文字列としてコンテキストに設定します。 * * @name Filters#postParameter * @see Context#postParameter */ exports.pre = function(context, next) { var req = context.req; if (req.method in ignoreMethods) { next(); return; } if (req.headers["content-type"] !== "application/x-www-form-urlencoded") { next(); return; } var buf = ""; req.setEncoding("UTF-8"); var onData = function(chunk) { buf += chunk; }; var onEnd = function(chunk) { req.removeListener("data", onData); req.removeListener("end", onEnd); context.postParameter = buf; this.__parameters__ = null; next(); }; req.on("data", onData); req.on("end", onEnd); };