Skip to content

Commit

Permalink
ch09 refactoring
Browse files Browse the repository at this point in the history
- removed `http` since it's duplicate of `ch06.asyncHttp`
  • Loading branch information
spamegg1 committed Apr 13, 2024
1 parent 7db9181 commit 36fbae9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 159 deletions.
12 changes: 5 additions & 7 deletions src/main/scala/ch06/asyncHttp/http.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ object HTTP:

def scanRequestLine(line: CString): (String, String, Int) =
val lineLen = stackalloc[Int](1)
val scanResult = stdio.sscanf(
line,
c"%s %s %*s\r\n%n",
methodBuffer,
uriBuffer,
lineLen
)
val scanResult =
stdio.sscanf(line, c"%s %s %*s\r\n%n", methodBuffer, uriBuffer, lineLen)
if scanResult == 2 then (fromCString(methodBuffer), fromCString(uriBuffer), !lineLen)
else throw Exception("bad request line")

Expand All @@ -62,12 +57,15 @@ object HTTP:
val startOfKey = line
val endOfKey = line + !keyEnd
!endOfKey = 0

val startOfValue = line + !valueStart
val endOfValue = line + !valueEnd
!endOfValue = 0

val key = fromCString(startOfKey)
val value = fromCString(startOfValue)
outMap(key) = value

!lineLen
else throw Exception("bad header line")

Expand Down
151 changes: 0 additions & 151 deletions src/main/scala/ch09/lmdbWeb/http.scala

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/scala/ch09/lmdbWeb/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import scalanative.libc.{stdlib, string}, stdlib.malloc
import argonaut.{Argonaut, EncodeJson, DecodeJson}
import Argonaut.{StringToParseWrap, ToJsonIdentity}

import ch03.http.{HttpRequest, HttpResponse}

val addPatn = raw"/add/([^/]+)/([^/]+)".r
val fetchPatn = raw"/fetch/([^/]+)".r
val listPatn = raw"/list/([^/]+)".r
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/ch09/lmdbWeb/server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import scalanative.unsafe.*
import scalanative.libc.{stdlib, string}, stdlib.malloc

object Server:
import LibUV.*, ch07.LibUVConstants.*, HTTP.RequestHandler
import LibUV.*, ch07.LibUVConstants.*
import ch06.asyncHttp.HTTP, HTTP.RequestHandler
import ch03.http.{HttpRequest, HttpResponse}

type ClientState = CStruct3[Ptr[Byte], CSize, CSize]

Expand Down

0 comments on commit 36fbae9

Please sign in to comment.