Coder Social home page Coder Social logo

alexciesielski / harproxyserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yaacov/harproxyserver

0.0 0.0 0.0 400 KB

HAR Proxy Server is a simple proxy server that records and plays back HTTP requests and responses in HAR format. It can be used as a standalone executable or integrated into other projects as an npm package.

License: Apache License 2.0

JavaScript 23.01% TypeScript 76.99%

harproxyserver's Introduction

npm version

HAR Proxy Server

HAR Proxy Server is a simple proxy server that records and plays back HTTP requests and responses in HAR format. It can be used as a standalone executable or integrated into other projects as an npm package.

Features

  • Record HTTP requests and responses to a HAR file.
  • Playback recorded requests and responses from a HAR file
  • Serve requests over HTTP or HTTPS.
  • Configurable playback endpoint prefix
  • Middleware support for Express.js.
  • Command-line interface for easy configuration
  • Utility to filter HAR files to extract only required HTTP/S requiests.
  • Utility to sanitize headers and cookies from har files

Installation

To install the server as a global command-line utility:

npm install --location=global harproxyserver

Usage

Standalone Executable

Run the server using the harServer command:

Start the server in play mode (default)

harproxyserver -p 3000 -f recorded.har

Start the server in record mode

harproxyserver -p 3000 -t http://example.com -f recorded.har -m record

Start the server with HTTPS

harproxyserver -p 3000 -f recorded.har --tls --key-file server.key --cert-file serv

Filter HAR file, to return only requests containing "forklift.konveyor.io" or "forklift-console-plugin" in the URL.

node dist/harProxyServer.js -m filter -f recorded.har --filter-endpoint-regexp "forklift.konveyor.io|forklift-console-plugin"

API

Import the server and utility functions in your TypeScript project:

import { findHarEntry, recordedHarMiddleware } from 'harproxyserver';

Example 1: Using findHarEntry to find a specific GET request in a HAR log:

const harLog = ... // retrieve HAR log
const method = 'GET';
const pathname = '/api';

const entry = findHarEntry(harLog, method, pathname);

if (entry) {
  console.log(`Found entry with ID ${entry.id}`);
} else {
  console.log('Entry not found');
}

Example 2: Using findHarEntry to find a POST request with specific query parameters:

const harLog = ... // retrieve HAR log
const method = 'POST';
const baseUrl = 'https://example.com/api';
const queryParams = { q: 'search term', page: 1 };

const url = new URL(baseUrl);
for (const [key, value] of Object.entries(queryParams)) {
  url.searchParams.set(key, value);
}
const pathnameWithParams = `${url.pathname}${url.search};

const entry = findHarEntry(harLog, method, pathnameWithParams);

if (entry) {
  console.log(`Found entry with ID ${entry.id}`);
} else {
  console.log('Entry not found');
}

Command-Line Options

The available options for this tool are:

  • --port, -p : The port the server will listen on (default: 3000).
  • --target-url, -t : The target URL to proxy when in 'record' mode.
  • --har-file, -f : The file path to save the HAR file (default: recording-[date and time].har).
  • --prefix : The prefix for the HAR playback endpoint (default: '').
  • --mode, -m : The mode to run the server in (default: 'play'). Choices are 'play', 'record' or 'filter'.
  • --tls: Run the server in secure mode (HTTPS) (default: false).
  • --key-file : Path to the TLS private key file (required when using --tls).
  • --cert-file : Path to the TLS certificate file (required when using --tls).
  • --filter-endpoint-regexp : RegExp to use when filtering a har file (filtered har file will include only matching endpoints)
  • --sanitize : Remove headers and cookies when filtering a har file

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

harproxyserver's People

Contributors

yaacov avatar alexciesielski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.