Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # raw-body
  2. [![NPM version](https://badge.fury.io/js/raw-body.svg)](http://badge.fury.io/js/raw-body)
  3. [![Build Status](https://travis-ci.org/stream-utils/raw-body.svg?branch=master)](https://travis-ci.org/stream-utils/raw-body)
  4. [![Coverage Status](https://img.shields.io/coveralls/stream-utils/raw-body.svg?branch=master)](https://coveralls.io/r/stream-utils/raw-body)
  5. Gets the entire buffer of a stream either as a `Buffer` or a string.
  6. Validates the stream's length against an expected length and maximum limit.
  7. Ideal for parsing request bodies.
  8. ## API
  9. ```js
  10. var getRawBody = require('raw-body')
  11. var typer = require('media-typer')
  12. app.use(function (req, res, next) {
  13. getRawBody(req, {
  14. length: req.headers['content-length'],
  15. limit: '1mb',
  16. encoding: typer.parse(req.headers['content-type']).parameters.charset
  17. }, function (err, string) {
  18. if (err)
  19. return next(err)
  20. req.text = string
  21. next()
  22. })
  23. })
  24. ```
  25. or in a Koa generator:
  26. ```js
  27. app.use(function* (next) {
  28. var string = yield getRawBody(this.req, {
  29. length: this.length,
  30. limit: '1mb',
  31. encoding: this.charset
  32. })
  33. })
  34. ```
  35. ### getRawBody(stream, [options], [callback])
  36. Returns a thunk for yielding with generators.
  37. Options:
  38. - `length` - The length length of the stream.
  39. If the contents of the stream do not add up to this length,
  40. an `400` error code is returned.
  41. - `limit` - The byte limit of the body.
  42. If the body ends up being larger than this limit,
  43. a `413` error code is returned.
  44. - `encoding` - The requested encoding.
  45. By default, a `Buffer` instance will be returned.
  46. Most likely, you want `utf8`.
  47. You can use any type of encoding supported by [iconv-lite](https://www.npmjs.org/package/iconv-lite#readme).
  48. You can also pass a string in place of options to just specify the encoding.
  49. `callback(err, res)`:
  50. - `err` - the following attributes will be defined if applicable:
  51. - `limit` - the limit in bytes
  52. - `length` and `expected` - the expected length of the stream
  53. - `received` - the received bytes
  54. - `encoding` - the invalid encoding
  55. - `status` and `statusCode` - the corresponding status code for the error
  56. - `type` - either `entity.too.large`, `request.size.invalid`, `stream.encoding.set`, or `encoding.unsupported`
  57. - `res` - the result, either as a `String` if an encoding was set or a `Buffer` otherwise.
  58. If an error occurs, the stream will be paused, everything unpiped,
  59. and you are responsible for correctly disposing the stream.
  60. For HTTP requests, no handling is required if you send a response.
  61. For streams that use file descriptors, you should `stream.destroy()` or `stream.close()` to prevent leaks.
  62. ## License
  63. The MIT License (MIT)
  64. Copyright (c) 2013 Jonathan Ong me@jongleberry.com
  65. Permission is hereby granted, free of charge, to any person obtaining a copy
  66. of this software and associated documentation files (the "Software"), to deal
  67. in the Software without restriction, including without limitation the rights
  68. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  69. copies of the Software, and to permit persons to whom the Software is
  70. furnished to do so, subject to the following conditions:
  71. The above copyright notice and this permission notice shall be included in
  72. all copies or substantial portions of the Software.
  73. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  74. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  75. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  76. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  77. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  78. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  79. THE SOFTWARE.