Skip to content

Commit

Permalink
Merge branch 'release/0.8.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Feb 6, 2019
2 parents 60dd21b + 4b64af9 commit cf42e98
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [0.8.7] - 2019-02-06
### Changed
* Allow cross-origin

## [0.8.6] - 2019-02-05
### Fixed
* Fix web client to run on IE11
Expand Down Expand Up @@ -121,7 +125,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
* Docker automated build on Docker Hub
* Support HTTPS

[Unreleased]: https://github.com/nwtgck/piping-server/compare/v0.8.6...HEAD
[Unreleased]: https://github.com/nwtgck/piping-server/compare/v0.8.7...HEAD
[0.8.7]: https://github.com/nwtgck/piping-seraver/compare/v0.8.6...v0.8.7
[0.8.6]: https://github.com/nwtgck/piping-seraver/compare/v0.8.5...v0.8.6
[0.8.5]: https://github.com/nwtgck/piping-seraver/compare/v0.8.4...v0.8.5
[0.8.4]: https://github.com/nwtgck/piping-seraver/compare/v0.8.3...v0.8.4
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "piping-server",
"version": "0.8.6",
"version": "0.8.7",
"description": "Streaming Data Transfer Server over HTTP/HTTPS",
"bin": {
"piping-server": "dist/src/index.js"
Expand Down
11 changes: 11 additions & 0 deletions src/piping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,16 @@ export class Server {
}
};

// Common headers for receivers
const commonHeaders: http.OutgoingHttpHeaders = {
"Access-Control-Allow-Origin": "*"
};

const headers: http.OutgoingHttpHeaders =
// If not multi-part sending
part === undefined ?
{
...commonHeaders,
// Add Content-Length if it exists
...(
sender.req.headers["content-length"] === undefined ?
Expand All @@ -330,6 +336,7 @@ export class Server {
)
} :
{
...commonHeaders,
// Add Content-Length if it exists
...(
part.byteCount === undefined ?
Expand Down Expand Up @@ -414,6 +421,10 @@ export class Server {
if (nReceivers === unestablishedPipe.nReceivers) {
// Register the sender
unestablishedPipe.sender = this.createSenderOrReceiver("sender", req, res, reqPath);
// Add headers
res.writeHead(200, {
"Access-Control-Allow-Origin": "*"
});
// Send waiting message
res.write(`[INFO] Waiting for ${nReceivers} receiver(s)...\n`);
// Send the number of receivers information
Expand Down
19 changes: 19 additions & 0 deletions test/piping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ describe("piping.Server", () => {
assert.equal(data.headers["content-type"], "text/plain");
});

it("should have Access-Control-Allow-Origin headers in GET/POST response", async () => {
// Get request promise
const reqPromise = thenRequest("GET", `${pipingUrl}/mydataid`);

// Send data
const postRes = await thenRequest("POST", `${pipingUrl}/mydataid`, {
body: "this is a content"
});

// Headers of POST response should have Access-Control-Allow-Origin
assert.equal(postRes.headers["access-control-allow-origin"], "*");

// Get data
const data = await reqPromise;

// Headers of GET response should have Access-Control-Allow-Origin
assert.equal(data.headers["access-control-allow-origin"], "*");
});

it("should handle connection (sender: O, receiver: O)", async () => {
// Send data
// (NOTE: Should NOT use `await` because of blocking a GET request)
Expand Down

0 comments on commit cf42e98

Please sign in to comment.