Skip to content

Commit 2079a61

Browse files
committed
use small time
1 parent ccf5006 commit 2079a61

File tree

9 files changed

+59
-20
lines changed

9 files changed

+59
-20
lines changed

.github/workflows/branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020

2121
publish:
2222
uses: ./.github/workflows/publish.yml
23-
24-
23+
secrets:
24+
PREFIX_API_KEY: ${{ secrets.PREFIX_API_KEY }}

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ jobs:
1818

1919
publish:
2020
uses: ./.github/workflows/publish.yml
21+
secrets:
22+
PREFIX_API_KEY: ${{ secrets.PREFIX_API_KEY }}
2123

2224

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Build and publish
22

33
on:
44
workflow_call:
5+
secrets:
6+
PREFIX_API_KEY:
7+
required: true
58

69
jobs:
710
publish:

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818

1919
publish:
2020
uses: ./.github/workflows/publish.yml
21+
secrets:
22+
PREFIX_API_KEY: ${{ secrets.PREFIX_API_KEY }}
2123

2224
upload-to-release:
2325
name: Upload to release

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Lightbug currently has the following features:
4040
- Bound Logger - [@toasty/stump](https://github.com/thatstoasty/stump)
4141
- Terminal text styling - [@toasty/mog](https://github.com/thatstoasty/mog)
4242
- CLI Library - [@toasty/prism](https://github.com/thatstoasty/prism)
43-
- Date/Time - [@mojoto/morrow](https://github.com/mojoto/morrow.mojo)
43+
- Date/Time - [@mojoto/morrow](https://github.com/mojoto/morrow.mojo) and [@toasty/small-time](https://github.com/thatstoasty/small-time)
4444

4545
<p align="right">(<a href="#readme-top">back to top</a>)</p>
4646

@@ -160,6 +160,7 @@ Create a file, e.g `client.mojo` with the following code. Run `magic run mojo cl
160160
from lightbug_http.http import HTTPRequest
161161
from lightbug_http.uri import URI
162162
from lightbug_http.sys.client import MojoClient
163+
from lightbug_http.strings import to_string
163164
164165
fn test_request(inout client: MojoClient) raises -> None:
165166
var uri = URI("http://httpbin.org/status/404")
@@ -168,19 +169,22 @@ fn test_request(inout client: MojoClient) raises -> None:
168169
except e:
169170
print("error parsing uri: " + e.__str__())
170171
172+
171173
var request = HTTPRequest(uri)
172174
var response = client.do(request)
173175
174-
print("Status Code:", response.header.status_code())
176+
# print status code
177+
print("Response:", response.header.status_code())
175178
176-
# print parsed headers (only selected headers are parsed for now)
177-
print("Content-Type:", String(response.header.content_type()))
179+
# print parsed headers (only some are parsed for now)
180+
print("Content-Type:", to_string(response.header.content_type()))
178181
print("Content-Length", response.header.content_length())
179-
print("Server:", String(response.header.server()))
182+
print("Server:", to_string(response.header.server()))
183+
180184
print("Is connection set to connection-close? ", response.header.connection_close())
181185
182186
# print body
183-
print(String(response.get_body_bytes()))
187+
print(to_string(response.get_body_bytes()))
184188
```
185189

186190
Pure Mojo-based client is available by default. This client is also used internally for testing the server.

lightbug_http/http.mojo

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from time import now
21
from utils.string_slice import StringSlice
32
from utils import Span
4-
# from external.morrow import Morrow
53
from gojo.strings.builder import StringBuilder
64
from gojo.bufio import Reader
5+
from small_time.small_time import now
76
from lightbug_http.uri import URI
87
from lightbug_http.io.bytes import Bytes, bytes
98
from lightbug_http.header import RequestHeader, ResponseHeader
@@ -340,12 +339,11 @@ fn encode(req: HTTPRequest) -> Bytes:
340339

341340

342341
fn encode(res: HTTPResponse) -> Bytes:
343-
# var current_time = String()
344-
# try:
345-
# current_time = Morrow.utcnow().__str__()
346-
# except e:
347-
# print("Error getting current time: " + str(e))
348-
# current_time = str(now())
342+
var current_time = String()
343+
try:
344+
current_time = now(utc=True).__str__()
345+
except e:
346+
print("Error getting current time: " + str(e))
349347

350348
var builder = StringBuilder()
351349

@@ -393,8 +391,8 @@ fn encode(res: HTTPResponse) -> Bytes:
393391
_ = builder.write_string(rChar)
394392
_ = builder.write_string(nChar)
395393

396-
_ = builder.write_string("Date: 12345")
397-
# _ = builder.write_string(current_time)
394+
_ = builder.write_string("Date: ")
395+
_ = builder.write_string(current_time)
398396

399397
_ = builder.write_string(rChar)
400398
_ = builder.write_string(nChar)

magic.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ environments:
5959
- conda: https://conda.anaconda.org/conda-forge/linux-64/pyzmq-26.2.0-py312hbf22597_2.conda
6060
- conda: https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8228510_1.conda
6161
- conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2
62+
- conda: https://repo.prefix.dev/mojo-community/linux-64/small_time-0.1.3-hb0f4dca_0.conda
6263
- conda: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda
6364
- conda: https://conda.anaconda.org/conda-forge/linux-64/tornado-6.4.1-py312h66e93f0_1.conda
6465
- conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda
@@ -108,6 +109,7 @@ environments:
108109
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/pyzmq-26.2.0-py312hc6335d2_2.conda
109110
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda
110111
- conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2
112+
- conda: https://repo.prefix.dev/mojo-community/osx-arm64/small_time-0.1.3-h60d57d3_0.conda
111113
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda
112114
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/tornado-6.4.1-py312h024a12e_1.conda
113115
- conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda
@@ -1435,6 +1437,34 @@ packages:
14351437
license_family: MIT
14361438
size: 14259
14371439
timestamp: 1620240338595
1440+
- kind: conda
1441+
name: small_time
1442+
version: 0.1.3
1443+
build: h60d57d3_0
1444+
subdir: osx-arm64
1445+
url: https://repo.prefix.dev/mojo-community/osx-arm64/small_time-0.1.3-h60d57d3_0.conda
1446+
sha256: 8f08a189fa15d96e6dc8b0cc49aecaefe9caf5a8209ca3ab5d2da91b7e13a3ba
1447+
depends:
1448+
- max >=24.5.0,<25
1449+
arch: arm64
1450+
platform: osx
1451+
license: MIT
1452+
size: 404869
1453+
timestamp: 1726265944269
1454+
- kind: conda
1455+
name: small_time
1456+
version: 0.1.3
1457+
build: hb0f4dca_0
1458+
subdir: linux-64
1459+
url: https://repo.prefix.dev/mojo-community/linux-64/small_time-0.1.3-hb0f4dca_0.conda
1460+
sha256: 6af5090414abb697ab570f48362ed2910b7188ee6df75ba4d7682d448428675f
1461+
depends:
1462+
- max >=24.5.0,<25
1463+
arch: x86_64
1464+
platform: linux
1465+
license: MIT
1466+
size: 404857
1467+
timestamp: 1726266228925
14381468
- kind: conda
14391469
name: tk
14401470
version: 8.6.13

mojoproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ publish = { cmd = "bash scripts/publish.sh", env = { PREFIX_API_KEY = "$PREFIX_A
1212

1313
[dependencies]
1414
max = ">=24.5.0,<25"
15-
gojo = "0.1.9"
15+
gojo = "0.1.9"
16+
small_time = "0.1.3"

tests/test_client.mojo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import testing
2-
from external.morrow import Morrow
32
from tests.utils import (
43
default_server_conn_string,
54
getRequest,

0 commit comments

Comments
 (0)