Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Oct 4, 2024
1 parent b43cb76 commit 4551a8f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 89 deletions.
57 changes: 2 additions & 55 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -136,61 +136,6 @@ public final class com/hexagontk/core/NetworkKt {
public static final fun urlOf (Ljava/lang/String;)Ljava/net/URL;
}

public final class com/hexagontk/core/Node : java/util/List, kotlin/jvm/internal/markers/KMappedMarker {
public fun <init> (Ljava/util/List;)V
public fun <init> (Ljava/util/Map;)V
public fun <init> ([Lkotlin/Pair;)V
public synthetic fun add (ILjava/lang/Object;)V
public fun add (ILkotlin/Pair;)V
public synthetic fun add (Ljava/lang/Object;)Z
public fun add (Lkotlin/Pair;)Z
public fun addAll (ILjava/util/Collection;)Z
public fun addAll (Ljava/util/Collection;)Z
public synthetic fun addFirst (Ljava/lang/Object;)V
public fun addFirst (Lkotlin/Pair;)V
public synthetic fun addLast (Ljava/lang/Object;)V
public fun addLast (Lkotlin/Pair;)V
public fun clear ()V
public final fun contains (Ljava/lang/Object;)Z
public fun contains (Lkotlin/Pair;)Z
public fun containsAll (Ljava/util/Collection;)Z
public synthetic fun get (I)Ljava/lang/Object;
public fun get (I)Lkotlin/Pair;
public final fun getList ()Z
public final fun getMap ()Z
public final fun getPairs ()Ljava/util/List;
public fun getSize ()I
public final fun indexOf (Ljava/lang/Object;)I
public fun indexOf (Lkotlin/Pair;)I
public fun isEmpty ()Z
public fun iterator ()Ljava/util/Iterator;
public final fun lastIndexOf (Ljava/lang/Object;)I
public fun lastIndexOf (Lkotlin/Pair;)I
public fun listIterator ()Ljava/util/ListIterator;
public fun listIterator (I)Ljava/util/ListIterator;
public synthetic fun remove (I)Ljava/lang/Object;
public fun remove (I)Lkotlin/Pair;
public fun remove (Ljava/lang/Object;)Z
public fun removeAll (Ljava/util/Collection;)Z
public synthetic fun removeFirst ()Ljava/lang/Object;
public fun removeFirst ()Lkotlin/Pair;
public synthetic fun removeLast ()Ljava/lang/Object;
public fun removeLast ()Lkotlin/Pair;
public fun replaceAll (Ljava/util/function/UnaryOperator;)V
public fun retainAll (Ljava/util/Collection;)Z
public synthetic fun set (ILjava/lang/Object;)Ljava/lang/Object;
public fun set (ILkotlin/Pair;)Lkotlin/Pair;
public final fun size ()I
public fun sort (Ljava/util/Comparator;)V
public fun subList (II)Ljava/util/List;
public fun toArray ()[Ljava/lang/Object;
public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object;
}

public final class com/hexagontk/core/NodeKt {
public static final fun f ()V
}

public final class com/hexagontk/core/OsKind : java/lang/Enum {
public static final field LINUX Lcom/hexagontk/core/OsKind;
public static final field MACOS Lcom/hexagontk/core/OsKind;
Expand Down Expand Up @@ -276,6 +221,7 @@ public final class com/hexagontk/core/media/MediaTypesKt {
public static final fun getAPPLICATION_BZIP2 ()Lcom/hexagontk/core/media/MediaType;
public static final fun getAPPLICATION_CBOR ()Lcom/hexagontk/core/media/MediaType;
public static final fun getAPPLICATION_COMPRESS ()Lcom/hexagontk/core/media/MediaType;
public static final fun getAPPLICATION_FORM_URLENCODED ()Lcom/hexagontk/core/media/MediaType;
public static final fun getAPPLICATION_GZIP ()Lcom/hexagontk/core/media/MediaType;
public static final fun getAPPLICATION_JAVA_ARCHIVE ()Lcom/hexagontk/core/media/MediaType;
public static final fun getAPPLICATION_JSON ()Lcom/hexagontk/core/media/MediaType;
Expand Down Expand Up @@ -316,6 +262,7 @@ public final class com/hexagontk/core/media/MediaTypesKt {
public static final fun getMEDIA_TYPE_FORMAT ()Lkotlin/text/Regex;
public static final fun getMULTIPART_ALTERNATIVE ()Lcom/hexagontk/core/media/MediaType;
public static final fun getMULTIPART_DIGEST ()Lcom/hexagontk/core/media/MediaType;
public static final fun getMULTIPART_FORM_DATA ()Lcom/hexagontk/core/media/MediaType;
public static final fun getMULTIPART_MIXED ()Lcom/hexagontk/core/media/MediaType;
public static final fun getMULTIPART_PARALLEL ()Lcom/hexagontk/core/media/MediaType;
public static final fun getTEXT_CALENDAR ()Lcom/hexagontk/core/media/MediaType;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/com/hexagontk/core/Node.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hexagontk.core

// TODO Other possible names: Struct or Record
class Node(val pairs: List<Pair<String?, *>>) : List<Pair<String?, *>> by pairs {
internal class Node(val pairs: List<Pair<String?, *>>) : List<Pair<String?, *>> by pairs {
val list: Boolean by lazy { pairs.all { it.first == null } }
val map: Boolean by lazy { !list }

Expand All @@ -18,7 +18,7 @@ class Node(val pairs: List<Pair<String?, *>>) : List<Pair<String?, *>> by pairs
}


fun f() {
internal fun f() {
Node(
mapOf("a" to 1)
)
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/kotlin/com/hexagontk/core/media/MediaTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ val APPLICATION_7Z: MediaType by lazy { MediaType(APPLICATION, "x-7z-compressed"
val APPLICATION_BZIP: MediaType by lazy { MediaType(APPLICATION, "x-bzip") }
val APPLICATION_BZIP2: MediaType by lazy { MediaType(APPLICATION, "x-bzip2") }
val APPLICATION_PHP: MediaType by lazy { MediaType(APPLICATION, "x-httpd-php") }
val APPLICATION_FORM_URLENCODED: MediaType by lazy {
MediaType(APPLICATION, "x-www-form-urlencoded")
}

val AUDIO_BASIC: MediaType by lazy { MediaType(AUDIO, "basic") }
val AUDIO_MPEG: MediaType by lazy { MediaType(AUDIO, "mpeg") }
Expand Down Expand Up @@ -61,7 +64,7 @@ val MULTIPART_ALTERNATIVE: MediaType by lazy { MediaType(MULTIPART, "alternative
val MULTIPART_DIGEST: MediaType by lazy { MediaType(MULTIPART, "digest") }
val MULTIPART_MIXED: MediaType by lazy { MediaType(MULTIPART, "mixed") }
val MULTIPART_PARALLEL: MediaType by lazy { MediaType(MULTIPART, "parallel") }
// TODO Add multipart/form-data
val MULTIPART_FORM_DATA: MediaType by lazy { MediaType(MULTIPART, "form-data") }

val TEXT_CSV: MediaType by lazy { MediaType(TEXT, "csv") }
val TEXT_X_JAVA_PROPERTIES: MediaType by lazy { MediaType(TEXT, "x-java-properties") }
Expand All @@ -85,6 +88,7 @@ val VIDEO_WEBM: MediaType by lazy { MediaType(VIDEO, "webm") }
val DEFAULT_MEDIA_TYPE: MediaType by lazy { APPLICATION_OCTET_STREAM }

// TODO Allow adding media types manually (allow resource loading, and keep here the bare minimum)
// With something like MediaTypeManager (as SerializationManager)
internal val MEDIA_TYPES_EXTENSIONS: Map<String, MediaType> by lazy {
mapOf(
"avro" to APPLICATION_AVRO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ internal class MediaTypeTest {
assertEquals("multipart/digest", MULTIPART_DIGEST.fullType)
assertEquals("multipart/mixed", MULTIPART_MIXED.fullType)
assertEquals("multipart/parallel", MULTIPART_PARALLEL.fullType)
assertEquals("multipart/form-data", MULTIPART_FORM_DATA.fullType)

assertEquals("text/event-stream", TEXT_EVENT_STREAM.fullType)

assertEquals("application/x-www-form-urlencoded", APPLICATION_FORM_URLENCODED.fullType)
}

@Test fun `Media types can be fetched from their file extensions`() {
Expand Down
12 changes: 12 additions & 0 deletions http/http/src/main/kotlin/com/hexagontk/http/model/HttpField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ interface HttpField {

operator fun minus(element: Any): HttpField
}

internal interface HttpValue {
val name: String
val value: Any?

fun string(): String? =
value?.toString()
}

internal interface HttpFields {

}
32 changes: 16 additions & 16 deletions http/http_handlers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ handlers.
This module is not meant to be used directly. You should include and Adapter implementing this
feature (as [http_server_jetty]) in order to create an HTTP server.

[http_server_jetty]: http_server_jetty
[http_server_jetty]: http_server_jetty.md

# Chaining changes
The response can be modified chaining `send` calls (or its utility methods). However, If calls are
Expand Down Expand Up @@ -77,17 +77,17 @@ methods.

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/SamplesTest.kt?serverCreation

[server settings]: api/http/http_server/com.hexagontk.http.server/-http-server-settings
[handlers section]: http_server/#handlers
[start()]: api/http/http_server/com.hexagontk.http.server/-http-server
[stop()]: api/http/http_server/com.hexagontk.http.server/-http-server
[server settings]: ../api/http/http_server/com.hexagontk.http.server/-http-server-settings
[handlers section]: #handlers
[start()]: ../api/http/http_server/com.hexagontk.http.server/-http-server
[stop()]: ../api/http/http_server/com.hexagontk.http.server/-http-server

## Servlet Web server
There is a special server adapter for running inside Servlet Containers. To use it you should import
the Servlet HTTP Server Adapter into your project. Check the [http_server_servlet] module for more
information.

[http_server_servlet]: http_server_servlet
[http_server_servlet]: http_server_servlet.md

# HTTP Context
These are the events that the handlers handle (they are also called HTTP calls or just calls along
Expand All @@ -103,7 +103,7 @@ full list of methods. This sample code illustrates the usage:

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/SamplesTest.kt?callbackCall

[API documentation]: api/http/http_handlers/com.hexagontk.http.handlers/-http-context
[API documentation]: ../api/http/http_handlers/com.hexagontk.http.handlers/-http-context

# Handlers
The main building blocks of Hexagon HTTP services are a set of handlers. A handler is made up of two
Expand Down Expand Up @@ -139,7 +139,7 @@ Check the next snippet for Handlers usage examples:

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/SamplesTest.kt?routesCreation

[next]: api/http/http_handlers/com.hexagontk.http.handlers/-http-context
[next]: ../api/http/http_handlers/com.hexagontk.http.handlers/-http-context

<!-- TODO Start document review -->

Expand All @@ -157,7 +157,7 @@ the following fields:

It yields true if all the supplied fields matches a call context.

[HttpPredicate]: api/http/http_handlers/com.hexagontk.http.handlers/-http-predicate
[HttpPredicate]: ../api/http/http_handlers/com.hexagontk.http.handlers/-http-predicate

## Path Patterns
Patterns to match requests paths. They can have:
Expand Down Expand Up @@ -294,15 +294,15 @@ Check the next example for details:
The media types of static files are computed from the file extension using the utility methods of
the [com.hexagontk.core.media] package.

[com.hexagontk.core.media]: api/core/com.hexagontk.core.media
[com.hexagontk.core.media]: ../api/core/com.hexagontk.core.media

# CORS
CORS behaviour can be different depending on the path. You can attach different [CORS Callbacks] to
different handlers. Check the [CorsCallback][CORS Callbacks] class for more details.

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/CorsTest.kt?cors

[CORS Callbacks]: api/http/http_server/com.hexagontk.http.server.callbacks/-cors-callback
[CORS Callbacks]: ../api/http/http_server/com.hexagontk.http.server.callbacks/-cors-callback

# HTTPS
It is possible to start a secure server enabling HTTPS. For this, you have to provide a server
Expand All @@ -327,14 +327,14 @@ Below you can find a simple example to set up an HTTPS server and client with mu

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/HttpsTest.kt?https

[SslSettings]: api/http/http/com.hexagontk.http/-ssl-settings
[SslSettings]: ../api/http/http/com.hexagontk.http/-ssl-settings
[HTTP/2]: https://en.wikipedia.org/wiki/HTTP/2
[ALPN]: https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation
[Gradle]: https://gradle.org
[create sample certificates]: gradle/#certificates
[create sample certificates]: gradle.md/#certificates
[mutual TLS]: https://en.wikipedia.org/wiki/Mutual_authentication
[SslSettings.clientAuth]: api/http/http/com.hexagontk.http/-ssl-settings
[Request.certificateChain]: api/http/http/com.hexagontk.http.model/-http-request
[SslSettings.clientAuth]: ../api/http/http/com.hexagontk.http/-ssl-settings
[Request.certificateChain]: ../api/http/http/com.hexagontk.http.model/-http-request

# WebSockets
A Web Socket is an HTTP(S) connection made with the GET method and the `upgrade: websocket` and
Expand Down Expand Up @@ -405,4 +405,4 @@ Classes to model server HTTP messages (requests and responses). Built on top of
# Package com.hexagontk.http.model.ws
Classes to model server HTTP messages (requests and responses). Built on top of the [http] module.

[http]: http
[http]: http.md
30 changes: 15 additions & 15 deletions http/http_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ handlers.
This module is not meant to be used directly. You should include and Adapter implementing this
feature (as [http_server_jetty]) in order to create an HTTP server.

[http_server_jetty]: http_server_jetty
[http_server_jetty]: http_server_jetty.md

# Context on HTTP processing
An HTTP server is nothing more than a function that takes a request and returns a response. Requests
Expand Down Expand Up @@ -72,17 +72,17 @@ methods.

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/SamplesTest.kt?serverCreation

[server settings]: api/http/http_server/com.hexagontk.http.server/-http-server-settings
[handlers section]: http_server/#handlers
[start()]: api/http/http_server/com.hexagontk.http.server/-http-server
[stop()]: api/http/http_server/com.hexagontk.http.server/-http-server
[server settings]: ../api/http/http_server/com.hexagontk.http.server/-http-server-settings
[handlers section]: #handlers
[start()]: ../api/http/http_server/com.hexagontk.http.server/-http-server
[stop()]: ../api/http/http_server/com.hexagontk.http.server/-http-server

## Servlet Web server
There is a special server adapter for running inside Servlet Containers. To use it you should import
the Servlet HTTP Server Adapter into your project. Check the [http_server_servlet] module for more
information.

[http_server_servlet]: http_server_servlet
[http_server_servlet]: http_server_servlet.md

# HTTP Context
These are the events that the handlers handle (they are also called HTTP calls or just calls along
Expand All @@ -98,7 +98,7 @@ full list of methods. This sample code illustrates the usage:

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/SamplesTest.kt?callbackCall

[API documentation]: api/http/http_handlers/com.hexagontk.http.handlers/-http-context
[API documentation]: ../api/http/http_handlers/com.hexagontk.http.handlers/-http-context

# Handlers
The main building blocks of Hexagon HTTP services are a set of handlers. A handler is made up of two
Expand Down Expand Up @@ -134,7 +134,7 @@ Check the next snippet for Handlers usage examples:

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/SamplesTest.kt?routesCreation

[next]: api/http/http_handlers/com.hexagontk.http.handlers/-http-context
[next]: ../api/http/http_handlers/com.hexagontk.http.handlers/-http-context

<!-- TODO Start document review -->

Expand All @@ -152,7 +152,7 @@ the following fields:

It yields true if all the supplied fields matches a call context.

[HttpPredicate]: api/http/http_handlers/com.hexagontk.http.handlers/-http-predicate
[HttpPredicate]: ../api/http/http_handlers/com.hexagontk.http.handlers/-http-predicate

## Path Patterns
Patterns to match requests paths. They can have:
Expand Down Expand Up @@ -289,15 +289,15 @@ Check the next example for details:
The media types of static files are computed from the file extension using the utility methods of
the [com.hexagontk.core.media] package.

[com.hexagontk.core.media]: api/core/com.hexagontk.core.media
[com.hexagontk.core.media]: ../api/core/com.hexagontk.core.media

# CORS
CORS behaviour can be different depending on the path. You can attach different [CORS Callbacks] to
different handlers. Check the [CorsCallback][CORS Callbacks] class for more details.

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/CorsTest.kt?cors

[CORS Callbacks]: api/http/http_server/com.hexagontk.http.server.callbacks/-cors-callback
[CORS Callbacks]: ../api/http/http_server/com.hexagontk.http.server.callbacks/-cors-callback

# HTTPS
It is possible to start a secure server enabling HTTPS. For this, you have to provide a server
Expand All @@ -322,14 +322,14 @@ Below you can find a simple example to set up an HTTPS server and client with mu

@code http/http_test/src/main/kotlin/com/hexagontk/http/test/examples/HttpsTest.kt?https

[SslSettings]: api/http/http/com.hexagontk.http/-ssl-settings
[SslSettings]: ../api/http/http/com.hexagontk.http/-ssl-settings
[HTTP/2]: https://en.wikipedia.org/wiki/HTTP/2
[ALPN]: https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation
[Gradle]: https://gradle.org
[create sample certificates]: gradle/#certificates
[create sample certificates]: gradle.md/#certificates
[mutual TLS]: https://en.wikipedia.org/wiki/Mutual_authentication
[SslSettings.clientAuth]: api/http/http/com.hexagontk.http/-ssl-settings
[Request.certificateChain]: api/http/http/com.hexagontk.http.model/-http-request
[SslSettings.clientAuth]: ../api/http/http/com.hexagontk.http/-ssl-settings
[Request.certificateChain]: ../api/http/http/com.hexagontk.http.model/-http-request

# WebSockets
A Web Socket is an HTTP(S) connection made with the GET method and the `upgrade: websocket` and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import java.net.URL

/**
* Server that listen to HTTP connections on a port and address and route requests to handlers.
*
* TODO Allow light startup log
*/
data class HttpServer(
private val adapter: HttpServerPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.hexagontk.http.model.HttpProtocol

/**
* Server instance of one kind.
*
* TODO Replace startUp by listen(address, port)
*/
interface HttpServerPort {

Expand Down

0 comments on commit 4551a8f

Please sign in to comment.