Skip to content
Snippets Groups Projects
  1. Sep 03, 2023
  2. Aug 10, 2023
  3. Jul 28, 2023
  4. Jul 10, 2023
    • Will McCutchen's avatar
      Add tests for correct handling of Expect: 100-continue (#138) · 3761c4ae
      Will McCutchen authored
      Issue #129 prompted me to look into how go-httpbin actually handles
      incoming requests that specify an `Expect: 100-continue` header. Here we
      add additional unit tests to explicitly codify the, uh, _expected_
      behavior for those requests.
      
      Note that the Go stdlib http client and server implementations have
      automagical `Expect: 100-continue` handling, which means
      these particular tests need to be written at a slightly lower level, by
      directly writing to and reading from the underlying TCP connection.
      
      Now, it may well be that the the moving parts (e.g. load balancers)
      between a client and the instances of go-httpbin deployed at
      https://httpbingo.org intervene and change this behavior, but these
      tests give me some confidence that, at least when such requests are made
      directly to go-httpbin itself, we are correctly handling them.
      3761c4ae
    • Will McCutchen's avatar
      Consistently parse and validate user-provided status codes (#137) · c9f4177d
      Will McCutchen authored
      In testing out error handling after #135, I happened to stumble across
      an unexpected panic for requests like `/status/1024` where the
      user-provided status code is outside the legal bounds. So, here we take
      a quick pass to ensure we're parsing and validating status codes the
      same way everywhere.
  5. Jul 01, 2023
    • Will McCutchen's avatar
      Improve and standardize error handling (#135) · 9e306405
      Will McCutchen authored
      Standardize on structured JSON error responses everywhere we can, with
      only one exception where the error is a warning for humans to read.
      
      Fixes #108 by adding a check to every request in the test suite to
      ensure that errors are never served with a Content-Type that might
      enable XSS or other vulnerabilities.
      
      While we're at it, continue refining the test suite and further adopting
      some of the testing helpers added in #131.
      9e306405
  6. Jun 29, 2023
    • Will McCutchen's avatar
      Standardize common content types (#134) · a43ddc85
      Will McCutchen authored
      Cleans up inconsistent and incorrect content types for plain text, html,
      JSON, and binary responses.
      a43ddc85
    • Will McCutchen's avatar
      Always consume body in tests (#133) · 443eb15a
      Will McCutchen authored
      A set of test suite improvements following up on #131:
      - Make sure we always fully consume and close response bodies, to allow
      the shared HTTP client to reuse connections to the local test server
      whenever possible
      - Make order of arguments to equality assertions consistent, so failed
      test output makes sense
      443eb15a
    • Will McCutchen's avatar
      Improve /drip semantics (#132) · a6709422
      Will McCutchen authored
      This started with me wading into the `/drip` endpoint to add
      `Server-Timing` trailers as suggested in
      https://github.com/mccutchen/go-httpbin/issues/72.
      
      In making those changes, I discovered that the standard golang net/http
      server we're building on only supports sending trailers when the
      response is written using `Content-Encoding: chunked`. Initially, I
      thought it would be reasonable for this endpoint, which is designed to
      stream writes to the client, to switch over to a chunked response, but
      upon further consideration I don't think that's a good idea. So I'll
      defer adding trailers to some later work.
      
      But, in thinking this through (and fighting with the unit tests already
      in place for drip), I realized that the `/drip` endpoint had room for
      improvement, if we think about it as an endpoint _designed to let
      clients test their behavior when an HTTP server is responding very
      slowly_.
      
      So, we ended up with these changes:
      
      Initial delay semantics:
      - Originally, `/drip` would immediately write the desired status code
      and then wait for the initial delay (if any).
      - Here we update that so that it waits for the initial delay before
      writing anything to the response, to better simulate a server that is
      just very slow to respond at all.
      
      Incremental write timings:
      - Switch over to a ticker to more accurately pace the incremental writes
      across the requested duration
      - Stop sleeping after the final byte is written (should not affect
      clients, but avoids wasting server resources)
      
      Worth noting that I now believe it's important that this endpoint
      **not** switch over to chunked content encoding, because it is useful to
      maintain and endpoint that simulates a server very slowly writing a
      "normal" HTTP response.
      a6709422
  7. Jun 28, 2023
    • Will McCutchen's avatar
      Refactor test suite to make real requests to a real server (#131) · 0de8ec96
      Will McCutchen authored
      In the course of validating #125, we discovered that using the stdlib's
      [`httptest.ResponseRecorder`][0] mechanism to drive the vast majority of
      our unit tests led to some slight brokenness due to subtle differences
      in the way those "simulated" requests are handled vs "real" requests to
      a live HTTP server, as [explained in this comment][1].
      
      That prompted me to do a big ass refactor of the entire test suite,
      swapping httptest.ResponseRecorder for interacting with a live server
      instance via [`httptest.Server`][2].
      
      This should make the test suite more accurate and reliable in the long
      run by ensuring that the vast majority of tests are making actual HTTP
      requests and reading responses from the wire.
      
      Note that updating these tests also uncovered a few minor bugs in
      existing handler code, fixed in a separate commit for visibility.
      
      P.S. I'm awfully sorry to anyone who tries to merge or rebase local test
      changes after this refactor lands, that is goign to be a nightmare. If
      you run into issues resolving conflicts, feel free to ping me and I can
      try to help!
      
      [0]: https://pkg.go.dev/net/http/httptest#ResponseRecorder
      [1]: https://github.com/mccutchen/go-httpbin/pull/125#issuecomment-1596176645
      [2]: https://pkg.go.dev/net/http/httptest#Server
      0de8ec96
  8. Jun 26, 2023
  9. Jun 21, 2023
  10. Jun 18, 2023
    • Bill Mill's avatar
      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
      }
      ```
    • Bill Mill's avatar
      feat: add method property to responses (#123) · 1223a736
      Bill Mill authored
      ```console
      # before: httpbingo lacks the "method" field but httpbin.org has it
      $ curl -s https://httpbingo.org/anything | jq .method                                                                                                        9:31PM
      null
      $ curl -s https://httpbin.org/anything | jq .method
      "GET"
      
      # after: httpbingo has the method field!
      $ curl -s http://0.0.0.0:8080/anything | jq .method
      "GET"
      ```
      
      This was mentioned in #6, but then not listed in #91
      
      - I took the highly technical testing approach of adding a test for
      `Method` anywhere in `handlers_test.go` that mentioned `Args`; do you
      desire more tests? fewer tests?
      - Anywhere else I should add this field that I didn't already?
      
      For what it's worth, I discovered this when working on upgrading the
      testing for our [httpsnippet
      library](https://github.com/readmeio/httpsnippet); I wanted to use
      `go-httpbin` but our tests expect the method field to be present in the
      responses
      1223a736
  11. May 05, 2023
  12. May 02, 2023
  13. Apr 14, 2023
    • Will McCutchen's avatar
      Build & CI updates (#116) · c9f5002d
      Will McCutchen authored
      A few small tweaks:
      - Simplify makefile
      - Cancel in-progress CI jobs when new commits are pushed to a non-main
      branch
      - Drop manual codeql config now that GitHub supports automagical
      configuration
      c9f5002d
  14. Mar 13, 2023
  15. Feb 15, 2023
  16. Jan 31, 2023
  17. Jan 30, 2023
  18. Jan 17, 2023
  19. Nov 19, 2022
    • Will McCutchen's avatar
      Improve tests for streaming response endpoints (#105) · 1229cc69
      Will McCutchen authored
      A few small improvements to the test suite:
      - Ensure `/stream` and `/stream-bytes` endpoints actually use
      `Transfer-Encoding: chunked`, instead of inferring/hoping based on
      Content-Length header
      - Explicitly test that `/drip` actually does sleep between writing
      bytes, rather than inferring that it does based on entire response
      duration
      1229cc69
  20. Nov 16, 2022
  21. Nov 13, 2022
  22. Nov 11, 2022
Loading