openlang

What date formatting does a Gleam HTTP response header need?

I want to send a Date header. The required format looks like this:

Date: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
Date: Sun, 23 Oct 2016 08:29:01 GMT

This is my current attempt:

 import gleam/http/elli
 import gleam/http/response.{type Response}
 import gleam/http/request.{type Request}
 import gleam/bytes_builder.{type BytesBuilder}
 import birl

 // Set up an HTTP service
 //
 pub fn serve_incoming(_incoming: Request(t)) -> Response(BytesBuilder) {
   let payload = bytes_builder.from_string("Hello there!")

   response.new(200)
   |> response.prepend_header("content-type", "text/plain")
   |> response.prepend_header("server", "gleam")
   |> response.prepend_header("date", birl.to_iso8601(birl.now()))
   |> response.set_body(payload)
 }

 pub fn main() {
   elli.become(serve_incoming, on_port: 8181)
 }

The conversation continues 3

Follow the reasoning
  1. Permalink

    birl provides format_date, which you could call for this:

     import gleam/http/elli
     import gleam/http/response.{type Response}
     import gleam/http/request.{type Request}
     import gleam/bytes_builder.{type BytesBuilder}
     import birl
     import time.{Iso8601}
    
     // Set up an HTTP service
     //
     pub fn serve_incoming(_incoming: Request(t)) -> Response(BytesBuilder) {
       let payload = bytes_builder.from_string("Hello there!")
    
       response.new(200)
       |> response.prepend_header("content-type", "text/plain")
       |> response.prepend_header("server", "gleam")
       |> response.prepend_header("date", http_date(birl.now()))
       |> response.set_body(payload)
     }
    
     fn http_date(moment: Iso8601) -> String {
       let formatted = birl.format_date(moment, "EEE, dd MMM yyyy HH:mm:ss 'GMT'")
       formatted
     }
    
     pub fn main() {
       elli.become(serve_incoming, on_port: 8181)
     }

Other sides of the same question

  1. Making the sender appear as a label instead of an email address using Java Mail

    Im sending messages through the Java Mail API. On arrival, the inbox displays the address that sent the message. Id like some…

    Replies 2Latest activity java
  2. Dynamics CRM access from TypeScript

    Because my CRM code runs in a webresource, I have to write to retrieve the entity's data. Regrettably, that expression fails…

    Replies 2Latest activity typescript
  3. Fastest approach for filling a Mat region with zero using OpenCV C++?

    What would be the most efficient approach for filling one area within a grayscale Mat image with zeros (or, indeed, with anot…

    Replies 3Latest activity cpp