Темы

ijson in Rust
I'm learning Rust by re-implementing my streaming JSON parser originally written in Python

Другие темы…

Статьи (feed)

Treat HTTP status codes as strings

13.05

I usually see HTTP status codes being checked as integer numbers:

if ((status >= 200) && (status < 300)) // or `<= 299`

This is rather verbose. But if you think about it, it's the first digit in the number that has a special value, and there are only five of them:

  • 1xx: server programmer is too smart
  • 2xx: success
  • 3xx: your client HTTP library is too dumb
  • 4xx: you screwed up
  • 5xx: server screwed up

When treated as strings, checking for the error class looks a bit better:

if (status[0] == '2')

Unfortunately, the ensuing party is pre-pooped by most client HTTP libraries helpfully casting the status to int.

Dear HTTP client libraries! Consider adding response.error_class to your responses.

Status update: 2016

20.11

Liberal JSON

20.08

highlight.js turns 10

16.08

Why Rust's ownership/borrowing is hard

11.02

ijson in Rust: typed lexer

11.11

Cadence for highlight.js

09.09

ijson in Rust: errors

26.08

Versioning REST: another angle

27.07

Versioning: follow-up

24.07

Архив…

Комментарии (feed)