Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
ADDED expose Browser.Request, Browser.Response and Browser.Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Apr 19, 2015
1 parent 005b472 commit 6dfdd38
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Version 4.0.8 2015-04-16
## Version 4.0.8 2015-04-19

Upgraded to JSDOM 5.0.1

ADDED expose Browser.Request, Browser.Response and Browser.Headers

694 passing (22s)
12 pending


## Version 4.0.7 2015-04-10
Expand Down
22 changes: 11 additions & 11 deletions src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class Headers {
const caseInsensitive = name.toLowerCase();
const castValue = String(value).replace(/\r\n/g, '');
let replaced = false;
this._headers = this._headers.reduce((headers, [name, value])=> {
if (name !== caseInsensitive)
headers.push([name, value]);
this._headers = this._headers.reduce((memo, header)=> {
if (header[0] !== caseInsensitive)
memo.push(header);
else if (!replaced) {
headers.push([name, castValue]);
memo.push([header[0], castValue]);
replaced = true;
}
return headers;
return memo;
}, []);

if (!replaced)
Expand Down Expand Up @@ -108,7 +108,7 @@ class FormData {
this._entries = [];
}

append(name, value, filename) {
append(name, value /*, filename*/) {
// TODO add support for files
this._entries.push([name, value]);
}
Expand All @@ -123,8 +123,8 @@ class FormData {
}

get(name) {
const entry = _.find(this._entries, entry => entry[0] === name);
return entry ? entry[1] : null;
const namedEntry = _.find(this._entries, entry => entry[0] === name);
return namedEntry ? namedEntry[1] : null;
}

getAll(name) {
Expand All @@ -134,8 +134,8 @@ class FormData {
}

has(name) {
const entry = _.find(this._entries, entry => entry[0] === name);
return !!entry;
const namedEntry = _.find(this._entries, entry => entry[0] === name);
return !!namedEntry;
}

[Symbol.iterator]() {
Expand Down Expand Up @@ -228,7 +228,7 @@ class Body {
}

async formData() {
const buffer = await this._consume();
await this._consume();
const contentType = this.headers.get('Content-Type') || '';
const mimeType = contentType.split(';')[0];
switch (mimeType) {
Expand Down
49 changes: 25 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DOM = require('./dom');
const { EventEmitter } = require('events');
const EventLoop = require('./eventloop');
const { format } = require('util');
const Fetch = require('./fetch');
const File = require('fs');
const Mime = require('mime');
const ms = require('ms');
Expand All @@ -28,7 +29,7 @@ const VERSION = require(`${__dirname}/../package.json`).version;
// Browser options you can set when creating new browser, or on browser instance.
const BROWSER_OPTIONS = ['features', 'headers', 'waitDuration',
'proxy', 'referrer', 'silent', 'site', 'strictSSL', 'userAgent',
'maxRedirects', 'language', 'runScripts', 'localAddress'];
'language', 'runScripts', 'localAddress'];

// These features are set on/off by default.
// Note that default values are actually prescribed where they are used,
Expand Down Expand Up @@ -1290,67 +1291,67 @@ class Browser extends EventEmitter {
return this._debugEnabled;
}

}

// -- Static properties --

static VERSION = VERSION

Object.assign(Browser, {
static Assert = Assert
static Pipeline = Pipeline
static Headers = Fetch.Headers
static Request = Fetch.Request
static Response = Fetch.Response

Assert,
Pipeline,
VERSION,

// -- These defaults are used in any new browser instance --

// Which features are enabled.
features: DEFAULT_FEATURES,

// Tells the browser how many redirects to follow before aborting a request. Defaults to 5
maxRedirects: 5,
static features = DEFAULT_FEATURES

// Proxy URL.
//
// Example
// Browser.proxy = 'http://myproxy:8080'
proxy: null,
static proxy = null

// If true, supress `console.log` output from scripts (ignored when DEBUG=zombie)
silent: false,
static silent = false

// You can use visit with a path, and it will make a request relative to this host/URL.
site: null,
static site = null

// Check SSL certificates against CA. False by default since you're likely
// testing with a self-signed certificate.
strictSSL: false,
static strictSSL = false

// Sets the outgoing IP address in case there is more than on available.
// Defaults to 0.0.0.0 which should select default interface
localAddress: '0.0.0.0',
static localAddress = '0.0.0.0'

// User agent string sent to server.
userAgent: `Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/${VERSION}`,
static userAgent = `Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/${VERSION}`

// Navigator language code
language: 'en-US',
static language = 'en-US'

// Default time to wait (visit, wait, etc).
waitDuration: '5s',
static waitDuration = '5s'

// Indicates whether or not to validate and execute JavaScript, default true.
runScripts: true,
static runScripts = true


// -- Internal properties --

// Debug instance. Create new instance when enabling debugging with Zombie.debug
_debug: debug('zombie'),
static _debug = debug('zombie')

// Set after calling _enableDebugging
_debugEnabled: null,
static _debugEnabled = null

// Browser extensions;
_extensions: []

});
static _extensions = []
}


module.exports = Browser;
Expand Down

0 comments on commit 6dfdd38

Please sign in to comment.