ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 206 forks source link

Fix request proxy bug due to "Content-Length" header #189

Closed eladnava closed 8 years ago

eladnava commented 8 years ago

This PR closes #97, an issue regarding specifying a custom proxy for node-gcm requests.

Due to a bug with the request module (explained in #97), the initial HTTP CONNECT request never succeeds.

This commit works around the issue by:

  1. Removing hard-coded declarations of Content-Type and Content-Length headers (request will add them automatically if we supply json payload)
  2. Supply the request body in the json parameter (as an object - not as a JSON-stringified string)
  3. Remove the parseAndRespond function which is no longer needed, as request returns a JSON object (it parses it for us)

Also, lots of tests relied on the way things worked before, with the body parameter, the custom content headers, and our own response JSON parsing. Updated them all, and they all pass.

  1. Changed request.body lookups to request.json (in request options)
  2. No need to JSON.parse() the request body anymore
  3. Bad JSON error will be thrown by request module
hypesystem commented 8 years ago

This is really just fantastic! Keep up the great work @eladnava :+1: :smile: :star:

eladnava commented 8 years ago

Thanks mate =) @hypesystem