How to use the http-status.UNSUPPORTED_MEDIA_TYPE function in http-status

To help you get started, we’ve selected a few http-status examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepstreamIO / deepstream.io / dist / src / message / http / server.js View on Github external
_handlePost(request, response) {
        let parsedContentType;
        try {
            parsedContentType = contentType.parse(request);
        }
        catch (typeError) {
            parsedContentType = { type: null };
        }
        if (parsedContentType.type !== 'application/json') {
            Server._terminateResponse(response, HTTPStatus.UNSUPPORTED_MEDIA_TYPE, 'Invalid "Content-Type" header. Supported media types: "application/json"');
            return;
        }
        this.jsonBodyParser(request, response, err => {
            if (err) {
                Server._terminateResponse(response, HTTPStatus.BAD_REQUEST, `Failed to parse body of request: ${err.message}`);
                return;
            }
            const onResponse = Server._onHandlerResponse.bind(null, response);
            const metadata = { headers: request.headers, url: request.url };
            if (this.config.enableAuthEndpoint && this.authPathRegExp.test(request.url)) {
                this.emit('auth-message', request.body, metadata, onResponse);
            }
            else if (this.postPathRegExp.test(request.url)) {
                this.emit('post-message', request.body, metadata, onResponse);
            }
            else {
github chadlung / jsonfeedserver / app.js View on Github external
app.post('/*', function(req, res){
    if(req.is('application/json')) {
        entry.save({body: req.body,
                    feed: req.params[0],
                    selfHref: config.server.domain + req.params[0]},
                    function(error, returnedEntry) {
            if(error) {
                res.send(error.message, httpStatus.INTERNAL_SERVER_ERROR);
            } else {
                res.send(returnedEntry, httpStatus.CREATED);
            }
        });
    } else {
        res.send(INVALID_JSON_ERROR, httpStatus.UNSUPPORTED_MEDIA_TYPE);
    }
});
github chadlung / jsonfeedserver / app.js View on Github external
app.use(function(err, req, res, next){
        res.send(INVALID_JSON_ERROR, httpStatus.UNSUPPORTED_MEDIA_TYPE);
    });
});
github deepstreamIO / deepstream.io / src / services / http / node / node-http.ts View on Github external
private handlePost (request: http.IncomingMessage, response: http.ServerResponse): void {
    let parsedContentType
    try {
      parsedContentType = contentType.parse(request)
    } catch (typeError) {
      parsedContentType = { type: null }
    }
    if (parsedContentType.type !== 'application/json') {
      this.terminateResponse(
        response,
        HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
        'Invalid "Content-Type" header. Supported media types: "application/json"'
      )
      return
    }

    this.jsonBodyParser(request, response, (err: Error | null) => {
      if (err) {
        this.terminateResponse(
          response,
          HTTPStatus.BAD_REQUEST,
          `Failed to parse body of request: ${err.message}`
        )
        return
      }

      for (const path of this.sortedPostPaths) {
github deepstreamIO / deepstream.io / src / connection-endpoint / http / node-server.ts View on Github external
private handlePost (request: any, response: any): void {
    let parsedContentType
    try {
      parsedContentType = contentType.parse(request)
    } catch (typeError) {
      parsedContentType = { type: null }
    }
    if (parsedContentType.type !== 'application/json') {
      Server.terminateResponse(
        response,
        HTTPStatus.UNSUPPORTED_MEDIA_TYPE,
        'Invalid "Content-Type" header. Supported media types: "application/json"'
      )
      return
    }

    this.jsonBodyParser(request, response, (err: Error | null) => {
      if (err) {
        Server.terminateResponse(
          response,
          HTTPStatus.BAD_REQUEST,
          `Failed to parse body of request: ${err.message}`
        )
        return
      }
      const onResponse = Server.onHandlerResponse.bind(null, response)
      const metadata = { headers: request.headers, url: request.url }