Skip to content

Responses with a status code of 204 are not made according to spec #865

@albertov

Description

@albertov

Description of the bug

According to the RFC7230 (http://tools.ietf.org/html/rfc7230#section-3.3.1):

A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content).

hoverfly seems to break this restriction when using https (at least) which may break clients (eg: snoyberg/http-client#408)

Steps to reproduce the issue

Add this pair to a simulation.json, hoverctl import it, set hoverfly in simulate mode (hoverctl mode simulate) and use the proxy with a client that gives no leeway (eg: http-client)

{
                                "request": {
                                        "path": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "/auth/tokens/jack-test-2"
                                                }
                                        ],
                                        "method": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "GET"
                                                }
                                        ],
                                        "destination": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "example.com"
                                                }
                                        ],
                                        "scheme": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "https"
                                                }
                                        ],
                                        "body": [
                                                {
                                                        "matcher": "exact",
                                                        "value": ""
                                                }
                                        ]
                                },
                                "response": {
                                        "status": 204,
                                        "encodedBody": false,
                                        "headers": {
                                                "Connection": [
                                                        "keep-alive"
                                                ],
                                                "Content-Type": [
                                                        "application/json;charset=utf-8"
                                                ],
                                                "Date": [
                                                        "Mon, 08 Jul 2019 15:04:19 GMT"
                                                ],
                                                "Hoverfly": [
                                                        "Was-Here"
                                                ],
                                                "Server": [
                                                        "nginx/1.15.8"
                                                ],
                                                "Strict-Transport-Security": [
                                                        "max-age=15724800; includeSubDomains"
                                                ]
                                        },
                                        "templated": false
                                }
                        }

Observed result

Hoverfly error messages seen (If none, say none)

none

If possible, add screenshots to help explain your problem

A decrypted dump of the response given by Hoverfly with request/response pair given above:

image

The response body (highlighted) is 0\r\n\r\n which appear to be the chunk header for 0-sized chunk (\0\r\n) and the empty terminated chunk itself (\r\n)

Expected result

The responses with 204 status code and 1xx shouldn't have the transfer-encoding: chunked header nor perform that encoding on the empty response body.

Additional relevant information

  1. Hoverfly version: cd51f9d with a patch to dump the private key to be able to decode the traffic with wireshark:
diff --git a/vendor/github.com/SpectoLabs/goproxy/signer.go b/vendor/github.com/SpectoLabs/goproxy/signer.go
index f6d99fc7..69d9de21 100644
--- a/vendor/github.com/SpectoLabs/goproxy/signer.go
+++ b/vendor/github.com/SpectoLabs/goproxy/signer.go
@@ -11,6 +11,9 @@ import (
        "runtime"
        "sort"
        "time"
+        "os"
+        "fmt"
+        "encoding/pem"
 )
 
 func hashSorted(lst []string) []byte {
@@ -76,6 +79,13 @@ func signHost(ca tls.Certificate, hosts []string) (cert tls.Certificate, err err
        if certpriv, err = rsa.GenerateKey(&csprng, 1024); err != nil {
                return
        }
+        pemPrivateFile, err := os.Create(hosts[0]+".private_key.pem")
+        if err != nil {
+            fmt.Println(err)
+            os.Exit(1)
+        }
+        pem.Encode(pemPrivateFile, &pem.Block{Type: "RSA PRIVATE KEY", Bytes:x509.MarshalPKCS1PrivateKey(certpriv) })
+        pemPrivateFile.Close()
        var derBytes []byte
        if derBytes, err = x509.CreateCertificate(&csprng, &template, x509ca, &certpriv.PublicKey, ca.PrivateKey); err != nil {
                return
  1. Anything that might help us to diagnose the problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions