Skip to content
Snippets Groups Projects
Select Git revision
  • a70a84787a073c90aa088244001fa7d091dfec6d
  • main default protected
  • drip-server-timing
  • compress-middleware
  • v2.11.0
  • v2.10.0
  • v2.9.2
  • v2.9.1
  • v2.9.0
  • v2.8.0
  • v2.7.0
  • v2.6.0
  • v2.5.6
  • v2.5.5
  • v2.5.4
  • v2.5.3
  • v2.5.2
  • v2.5.1
  • v2.5.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.0
  • v2.2.2
24 results

helpers.go

  • Bill Mill's avatar
    a70a8478
    fix: return empty data field for empty request bodies (#125) · a70a8478
    Bill Mill authored
    When a request to `/anything` has an empty body, the `data` field of the
    output should be the empty string. Currently, `go-httpbin is returning
    `data:application/octet-stream;base64,`.
    
    - Should the output actually be null? That would match `files`, `form`,
    and `json`, but also would require deeper changes since `Data` is stored
    as a string not a pointer, and I didn't want to mess with things any
    more than I had to. An empty string works fine for my purposes
    - how can I test this PR? I tried but I got confused by the TestAnything
    method
    - all the current tests pass under this change
    
    This PR closes #124. Before:
    
    ```
    $ curl -s 'http://0.0.0.0:8080/anything?one=two'
    {
      "args": {
        "one": [
          "two"
        ]
      },
      "headers": {
        "Accept": [
          "*/*"
        ],
        "Host": [
          "0.0.0.0:8080"
        ],
        "User-Agent": [
          "curl/7.88.1"
        ]
      },
      "method": "GET",
      "origin": "127.0.0.1:60402",
      "url": "http://0.0.0.0:8080/anything?one=two",
      "data": "data:application/octet-stream;base64,",
      "files": null,
      "form": null,
      "json": null
    }
    ```
    
    After:
    ```
    $ curl -s 'http://0.0.0.0:8080/anything?one=two'
    {
      "args": {
        "one": [
          "two"
        ]
      },
      "headers": {
        "Accept": [
          "*/*"
        ],
        "Host": [
          "0.0.0.0:8080"
        ],
        "User-Agent": [
          "curl/7.88.1"
        ]
      },
      "method": "GET",
      "origin": "127.0.0.1:60595",
      "url": "http://0.0.0.0:8080/anything?one=two",
      "data": "",
      "files": null,
      "form": null,
      "json": null
    }
    ```
    fix: return empty data field for empty request bodies (#125)
    Bill Mill authored
    When a request to `/anything` has an empty body, the `data` field of the
    output should be the empty string. Currently, `go-httpbin is returning
    `data:application/octet-stream;base64,`.
    
    - Should the output actually be null? That would match `files`, `form`,
    and `json`, but also would require deeper changes since `Data` is stored
    as a string not a pointer, and I didn't want to mess with things any
    more than I had to. An empty string works fine for my purposes
    - how can I test this PR? I tried but I got confused by the TestAnything
    method
    - all the current tests pass under this change
    
    This PR closes #124. Before:
    
    ```
    $ curl -s 'http://0.0.0.0:8080/anything?one=two'
    {
      "args": {
        "one": [
          "two"
        ]
      },
      "headers": {
        "Accept": [
          "*/*"
        ],
        "Host": [
          "0.0.0.0:8080"
        ],
        "User-Agent": [
          "curl/7.88.1"
        ]
      },
      "method": "GET",
      "origin": "127.0.0.1:60402",
      "url": "http://0.0.0.0:8080/anything?one=two",
      "data": "data:application/octet-stream;base64,",
      "files": null,
      "form": null,
      "json": null
    }
    ```
    
    After:
    ```
    $ curl -s 'http://0.0.0.0:8080/anything?one=two'
    {
      "args": {
        "one": [
          "two"
        ]
      },
      "headers": {
        "Accept": [
          "*/*"
        ],
        "Host": [
          "0.0.0.0:8080"
        ],
        "User-Agent": [
          "curl/7.88.1"
        ]
      },
      "method": "GET",
      "origin": "127.0.0.1:60595",
      "url": "http://0.0.0.0:8080/anything?one=two",
      "data": "",
      "files": null,
      "form": null,
      "json": null
    }
    ```