Non HTTP response to HTTP request (sorry)

1. My Caddy version (caddy -version):

Caddy v1.0.3

2. How I run Caddy:

a. System environment:

Debian 9, systemd

b. Command:

sudo systemctl start caddy.service

c. My complete Caddyfile:

https://sage.whiteteam.co.uk {
        log stdout
        errors stderr

        bind 0.0.0.0

        proxy / localhost:8090
}

3. The problem I’m having:

Context (please don’t shoot the messenger)

I am writing a ‘proof of concept’ sage pay server integration, the requirements for the integration are to expose an endpoint for sage pay to open an http (or https) request, and get a response of purely:

Status=OK
RedirectURL=https://some.domain.com/

No headers, no http protocol, no status, just the content.

Actual problem

I am proxying requests to a locally running Go http server, which hijacks the request and writes the above data to the connection. This ‘works’ if I make a request directly to the Go server, however if I use a Caddy proxy to point https requests I get the below error. The error makes sense (the response being written doesn’t conform to the http spec) but is there a way or circumventing this?

4. Error messages and/or full log output:

30/Oct/2019:09:09:51 +0000 [ERROR 502 /] net/http: HTTP/1.x transport connection broken: malformed HTTP response "Status=OK"

5. What I already tried:

As explained above I’ve tried binding the Go server port directly to 80 and all is fine, but I need Caddy as a proxy.

6. Links to relevant resources:

If anyone wants to laugh at my expense please see Elavon: Card Payment Solutions & Merchant Services

It’s because Caddy’s proxy directive is an HTTP proxy. If you want to break the HTTP spec then you have to either modify the HTTP proxy to support your spec violations, or proxy at a lower layer like TCP. Caddy 1 has a TCP proxy: https://caddyserver.com/v1/docs/net

(This is true for any proxy you’d put in front of such an application.)

Edit: Welcome, btw!

1 Like

Thanks for your reply Matt, much appreciated.

I had a feeling this would be the case, but I’ve not used Caddy to any great extent.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.