Skip to content

Commit

Permalink
standard
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Oct 29, 2020
1 parent e69456b commit a0fe9a3
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 124 deletions.
12 changes: 6 additions & 6 deletions test/auth.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var concat = require('simple-concat')
var get = require('../')
var http = require('http')
var test = require('tape')
const concat = require('simple-concat')
const get = require('../')
const http = require('http')
const test = require('tape')

test('basic auth', function (t) {
t.plan(5)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
t.equal(req.headers.authorization, 'Basic Zm9vOmJhcg==')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get('http://foo:bar@localhost:' + port, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
Expand Down
42 changes: 21 additions & 21 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
var concat = require('simple-concat')
var get = require('../')
var http = require('http')
var selfSignedHttps = require('self-signed-https')
var test = require('tape')
const concat = require('simple-concat')
const get = require('../')
const http = require('http')
const selfSignedHttps = require('self-signed-https')
const test = require('tape')

test('simple get', function (t) {
t.plan(5)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
t.equal(req.url, '/path')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get('http://localhost:' + port + '/path', function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
Expand All @@ -30,14 +30,14 @@ test('simple get', function (t) {
test('https', function (t) {
t.plan(5)

var server = selfSignedHttps(function (req, res) {
const server = selfSignedHttps(function (req, res) {
t.equal(req.url, '/path')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get({
url: 'https://localhost:' + port + '/path',
rejectUnauthorized: false
Expand All @@ -56,16 +56,16 @@ test('https', function (t) {
test('simple get json', function (t) {
t.plan(6)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
t.equal(req.url, '/path')
t.equal(req.headers.accept, 'application/json')
res.statusCode = 200
res.end('{"message":"response"}')
})

server.listen(0, function () {
var port = server.address().port
var opts = {
const port = server.address().port
const opts = {
url: 'http://localhost:' + port + '/path',
json: true
}
Expand All @@ -84,7 +84,7 @@ test('simple get json', function (t) {
test('HEAD request', function (t) {
t.plan(3)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
t.equal(req.method, 'HEAD')
// Taken from real-world response from HEAD request to GitHub.com
res.setHeader('content-type', 'text/html; charset=utf-8')
Expand All @@ -95,8 +95,8 @@ test('HEAD request', function (t) {
})

server.listen(0, function () {
var port = server.address().port
var opts = {
const port = server.address().port
const opts = {
method: 'HEAD',
url: 'http://localhost:' + port
}
Expand All @@ -111,7 +111,7 @@ test('HEAD request', function (t) {
test('timeout option', function (t) {
t.plan(2)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
t.equal(req.url, '/path')
setTimeout(function () {
// response should not be sent - should timeout before it's sent
Expand All @@ -120,7 +120,7 @@ test('timeout option', function (t) {
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get({
url: 'http://localhost:' + port + '/path',
timeout: 1000
Expand All @@ -134,9 +134,9 @@ test('timeout option', function (t) {
test('rewrite POST redirects to GET', function (t) {
t.plan(8)

var redirected = false
let redirected = false

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
if (redirected) {
t.equal(req.url, '/getthis')
t.equal(req.method, 'GET')
Expand All @@ -153,8 +153,8 @@ test('rewrite POST redirects to GET', function (t) {
})

server.listen(0, function () {
var port = server.address().port
var opts = {
const port = server.address().port
const opts = {
method: 'POST',
body: '123',
url: 'http://localhost:' + port
Expand Down
30 changes: 15 additions & 15 deletions test/concat.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var get = require('../')
var http = require('http')
var str = require('string-to-stream')
var test = require('tape')
const get = require('../')
const http = require('http')
const str = require('string-to-stream')
const test = require('tape')

test('get.concat (post, stream body, and json option)', function (t) {
t.plan(4)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
res.statusCode = 200
req.pipe(res)
})

server.listen(0, function () {
var port = server.address().port
var opts = {
const port = server.address().port
const opts = {
url: 'http://localhost:' + port,
body: str('{"a": "b"}'),
method: 'POST',
Expand All @@ -31,13 +31,13 @@ test('get.concat (post, stream body, and json option)', function (t) {

test('get.concat', function (t) {
t.plan(4)
var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
res.statusCode = 200
res.end('blah blah blah')
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get.concat('http://localhost:' + port, function (err, res, data) {
t.error(err)
t.equal(res.statusCode, 200)
Expand All @@ -50,14 +50,14 @@ test('get.concat', function (t) {

test('get.concat json', function (t) {
t.plan(3)
var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
res.statusCode = 200
res.end('{"message":"response"}')
})

server.listen(0, function () {
var port = server.address().port
var opts = {
const port = server.address().port
const opts = {
url: 'http://localhost:' + port + '/path',
json: true
}
Expand All @@ -72,14 +72,14 @@ test('get.concat json', function (t) {

test('get.concat json error', function (t) {
t.plan(1)
var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
res.statusCode = 500
res.end('not json')
})

server.listen(0, function () {
var port = server.address().port
var opts = {
const port = server.address().port
const opts = {
url: 'http://localhost:' + port + '/path',
json: true
}
Expand Down
24 changes: 12 additions & 12 deletions test/headers.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var concat = require('simple-concat')
var get = require('../')
var http = require('http')
var str = require('string-to-stream')
var test = require('tape')
var zlib = require('zlib')
const concat = require('simple-concat')
const get = require('../')
const http = require('http')
const str = require('string-to-stream')
const test = require('tape')
const zlib = require('zlib')

test('custom headers', function (t) {
t.plan(2)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
t.equal(req.headers['custom-header'], 'custom-value')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get({
url: 'http://localhost:' + port,
headers: {
Expand All @@ -32,14 +32,14 @@ test('custom headers', function (t) {
test('gzip response', function (t) {
t.plan(4)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
res.statusCode = 200
res.setHeader('content-encoding', 'gzip')
str('response').pipe(zlib.createGzip()).pipe(res)
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get('http://localhost:' + port, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200) // statusCode still works on gunzip stream
Expand All @@ -55,14 +55,14 @@ test('gzip response', function (t) {
test('deflate response', function (t) {
t.plan(4)

var server = http.createServer(function (req, res) {
const server = http.createServer(function (req, res) {
res.statusCode = 200
res.setHeader('content-encoding', 'deflate')
str('response').pipe(zlib.createDeflate()).pipe(res)
})

server.listen(0, function () {
var port = server.address().port
const port = server.address().port
get('http://localhost:' + port, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200) // statusCode still works on inflate stream
Expand Down
Loading

0 comments on commit a0fe9a3

Please sign in to comment.