Skip to content

Commit

Permalink
Proxy https protocol requests
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jan 16, 2014
1 parent 0ea8cc9 commit 9b6f506
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
16 changes: 8 additions & 8 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Fs = require 'fs'
Dns = require 'dns'
Url = require 'url'
Http = require 'http'
Https = require 'https'
Crypto = require 'crypto'
QueryString = require 'querystring'

Expand Down Expand Up @@ -74,12 +75,11 @@ process_url = (url, transferredHeaders, resp, remaining_redirects) ->
if !url.host?
return four_oh_four(resp, "Invalid host", url)

if url.protocol == 'https:'
error_log("Redirecting https URL to origin: #{url.format()}")
resp.writeHead 301, {'Location': url.format()}
finish resp
return
else if url.protocol != 'http:'
if url.protocol is 'https:'
Protocol = Https
else if url.protocol is 'http:'
Protocol = Http
else
four_oh_four(resp, "Unknown protocol", url)
return

Expand All @@ -105,11 +105,11 @@ process_url = (url, transferredHeaders, resp, remaining_redirects) ->

requestOptions =
hostname: url.hostname
port: url.port ? 80
port: url.port
path: queryPath
headers: transferredHeaders

srcReq = Http.get requestOptions, (srcResp) ->
srcReq = Protocol.get requestOptions, (srcResp) ->
is_finished = true

debug_log srcResp.headers
Expand Down
23 changes: 11 additions & 12 deletions server.js

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

0 comments on commit 9b6f506

Please sign in to comment.