Skip to content

new test: 100 continue #8

Open
Open
@Geal

Description

@Geal

The 100 HTTP status code needs special handling, because the server will do a first validation and send a response, then the client will send the rest of the response. It can be used when the client wants to send a huge file but check authorization before sending the actual data.

References:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/100

example server code:

const http = require('http');
const net = require('net');
const url = require('url');

const server = http.createServer()

// listen for checkContinue events
server.on('checkContinue', function(req, res) {
  console.log("check_continue")
  req.checkContinue = true;
  handlePostFile(req, res); // call express directly to route the request
});

// example request handler
function handlePostFile(req, res) {
  console.log("handle post file")


  // was this a conditional request?
  if (req.checkContinue === true) {
    req.checkContinue = false;
    // send 100 Continue response
    res.writeContinue();
    
    console.log("wrote continue");
    // client will now send us the request body
  }
  
  // collect request body
  var body = '';
  req.once('readable', function() {
    var chunk;
    console.log("readable()");

    while ((chunk = req.read()) !== null) {
      console.log("read");
      body += chunk;
    }

    // do something with request body
  });
}

server.listen(1029)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions