Skip to content

Commit

Permalink
Merge pull request #23 from serpapi/fix-22-multibyte-char-corruption
Browse files Browse the repository at this point in the history
Handle HTTP chunking across multi-byte boundaries
  • Loading branch information
zyc9012 authored Mar 12, 2024
2 parents 1cdcf24 + d9385fc commit ece9d5e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build

on: [push, pull_request]
on: [push]

jobs:
build:
Expand Down Expand Up @@ -52,6 +52,15 @@ jobs:
strategy:
matrix:
node-version: [7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x, 19.x]
include:
- command: test
- command: test:use-openssl-ca
node-version: 7.x
- command: test:use-openssl-ca
node-version: 8.x
- command: test:use-openssl-ca
node-version: 9.x

steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -76,7 +85,7 @@ jobs:
run: |
cd smoke_tests/commonjs
npm i
npm test
npm run ${{ matrix.command }}
smoke-tests-esm:
name: "Smoke tests (ESM)"
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ more.
### Node.js

- Supports Node.js 7.10.1 and newer.
- Refer to [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_7_up) for help.
- Refer to
[this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_7_up)
for help.

```bash
npm install serpapi
Expand All @@ -40,7 +42,9 @@ getJson({

- If you prefer using the `import` syntax and top-level `await`, you need to use
at least Node.js 14.8.0.
- Refer to [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_14_up) for help.
- Refer to
[this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/node/js_node_14_up)
for help.

You will need to add `"type": "module"` to your `package.json`:

Expand All @@ -66,7 +70,9 @@ console.log(response);

- Import directly from deno.land.
- Usage is otherwise the same as above.
- Refer to [this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/deno) for help.
- Refer to
[this example](https://github.com/serpapi/serpapi-javascript/tree/master/examples/deno)
for help.

```ts
import { getJson } from "https://deno.land/x/serpapi/mod.ts";
Expand Down
3 changes: 2 additions & 1 deletion smoke_tests/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"serpapi": "../../npm"
},
"scripts": {
"test": "node commonjs.js"
"test": "node commonjs.js",
"test:use-openssl-ca": "node --use-openssl-ca commonjs.js"
}
}
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function execute(
return new Promise((resolve, reject) => {
let timer: number;
const req = https.get(url, (resp) => {
resp.setEncoding("utf8");
let data = "";

// A chunk of data has been recieved.
Expand Down

0 comments on commit ece9d5e

Please sign in to comment.