Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
accept all valid images regardless of HTTP status, fixes #75
Browse files Browse the repository at this point in the history
  • Loading branch information
jomo committed Mar 21, 2015
1 parent 98b9bce commit 3134d7c
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions server.coffee
Expand Up @@ -136,25 +136,6 @@ process_url = (url, transferredHeaders, resp, remaining_redirects) ->
finish resp

switch srcResp.statusCode
when 200
contentType = newHeaders['content-type']

unless contentType?
srcResp.destroy()
four_oh_four(resp, "No content-type returned", url)
return

contentTypePrefix = contentType.split(";")[0]

unless contentTypePrefix in accepted_image_mime_types
srcResp.destroy()
four_oh_four(resp, "Non-Image content-type returned '#{contentTypePrefix}'", url)
return

debug_log newHeaders

resp.writeHead srcResp.statusCode, newHeaders
srcResp.pipe resp
when 301, 302, 303, 307
srcResp.destroy()
if remaining_redirects <= 0
Expand All @@ -174,8 +155,24 @@ process_url = (url, transferredHeaders, resp, remaining_redirects) ->
srcResp.destroy()
resp.writeHead srcResp.statusCode, newHeaders
else
srcResp.destroy()
four_oh_four(resp, "Origin responded with #{srcResp.statusCode}", url)
contentType = newHeaders['content-type']

unless contentType?
srcResp.destroy()
four_oh_four(resp, "No content-type returned", url)
return

contentTypePrefix = contentType.split(";")[0]

unless contentTypePrefix in accepted_image_mime_types
srcResp.destroy()
four_oh_four(resp, "Non-Image content-type returned '#{contentTypePrefix}'", url)
return

debug_log newHeaders

resp.writeHead srcResp.statusCode, newHeaders
srcResp.pipe resp

srcReq.setTimeout (socket_timeout * 1000), ->
srcReq.abort()
Expand Down

0 comments on commit 3134d7c

Please sign in to comment.