Skip to content

Commit

Permalink
HTTP context API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Sep 13, 2023
1 parent e9c300b commit b736a0e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 92 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

name: Build

on:
push:
branches-ignore: [ master ]
Expand All @@ -10,7 +8,6 @@ permissions:

jobs:
build:
name: Build
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: dev
Expand Down
42 changes: 11 additions & 31 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

name: Nightly

on:
schedule:
- cron: "59 23 * * *"
Expand Down Expand Up @@ -28,9 +26,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest ]
os: [ ubuntu-latest, windows-latest, macos-latest ]

name: Build (${{ matrix.os }})
name: build (${{ matrix.os }})
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
os: ${{ matrix.os }}
Expand All @@ -39,25 +37,13 @@ jobs:
check_directory: core/build
ref: develop

# TODO Delete this special case when Jacoco runs on macOS properly
build_macos:
name: Build (macos-latest)
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
os: macos-latest
java: dev
distribution: graalvm
check_directory: core/build
ref: develop
tasks: -x jacocoTestReport

sample_keystores:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]

name: Sample Keystores (${{ matrix.os }})
name: sample_keystores (${{ matrix.os }})
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
os: ${{ matrix.os }}
Expand All @@ -72,30 +58,25 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]

name: Native Test
name: native_test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
- name: Configure Page File
uses: al-cheb/configure-pagefile-action@v1.3
- uses: al-cheb/configure-pagefile-action@v1.3
if: ${{ matrix.os == 'windows-latest' }}
with:
minimum-size: 16GB
disk-root: "C:"
- name: Check Out
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
ref: develop
- name: Set Up Java
uses: graalvm/setup-graalvm@v1
- uses: graalvm/setup-graalvm@v1
with:
java-version: 20
distribution: graalvm-community
java-version: dev
distribution: graalvm
cache: gradle
- name: Build Project
run: ./gradlew --stacktrace nativeTest
- run: ./gradlew --stacktrace nativeTest

jmh:
name: JMH Benchmark
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: dev
Expand All @@ -104,7 +85,6 @@ jobs:
tasks: jmh

build_site:
name: Build Site
uses: hexagonkt/hexagon/.github/workflows/site.yml@master
with:
ref: develop
Expand All @@ -115,7 +95,7 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]

name: Test Publishing (${{ matrix.os }})
name: test_publishing (${{ matrix.os }})
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
os: ${{ matrix.os }}
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@

name: Pull Request

on:
- pull_request
on: pull_request

permissions:
contents: read

jobs:
sample_keystores:
name: Sample Keystores
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: dev
distribution: graalvm
tasks: createCa createIdentities

native_test:
name: Native Test
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: dev
distribution: graalvm
tasks: nativeTest

jmh:
name: JMH Benchmark
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: dev
distribution: graalvm
tasks: jmh

build_site:
name: Build Site
uses: hexagonkt/hexagon/.github/workflows/site.yml@develop

test_publishing:
name: Test Publishing
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: dev
Expand Down
21 changes: 6 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@

name: Release

on:
push:
branches: [ master ]

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:

- name: Restore MkDocs Cache
uses: actions/cache@v3
- uses: actions/cache@v3
with:
key: ${{ runner.os }}-mkdocs-${{ hashFiles('**/*.gradle*', '**/gradle*.properties') }}
restore-keys: ${{ runner.os }}-mkdocs-
path: |
~/.local/bin
~/.local/lib/python*/site-packages
- name: Check Out
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set Up Java
uses: graalvm/setup-graalvm@v1
- uses: graalvm/setup-graalvm@v1
with:
java-version: 20
distribution: graalvm-community
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: gradle

- name: Update Site
env:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export REMOTE="https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git"
Expand All @@ -44,16 +37,14 @@ jobs:
./gradlew -x build buildSite
ls -AlF site/build/site
- name: Publish Packages
env:
- env:
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew --no-daemon -x test release

- name: Publish Site
run: |
- run: |
cp -rf site/build/site/* build/gh-pages/
cd build/gh-pages
git add --all
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/release_branch.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@

name: Release Branch

on:
push:
branches: [ release/** ]

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:

- name: Check Out
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set Up Java
uses: graalvm/setup-graalvm@v1
- uses: graalvm/setup-graalvm@v1
with:
java-version: 20
distribution: graalvm-community
java-version: dev
distribution: graalvm
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: gradle

- name: Publish Packages
env:
- env:
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
Expand Down
21 changes: 6 additions & 15 deletions .github/workflows/site.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

name: Site

on:
workflow_call:
inputs:
Expand Down Expand Up @@ -31,41 +29,34 @@ on:

jobs:
site:
name: Build Site
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run: { shell: bash }
steps:
- name: Restore MkDocs Cache
uses: actions/cache@v3
- uses: actions/cache@v3
with:
key: ${{ runner.os }}-mkdocs-${{ hashFiles('**/*.gradle*', '**/gradle*.properties') }}
restore-keys: ${{ runner.os }}-mkdocs-
path: |
~/.local/bin
~/.local/lib/python*/site-packages
- name: Check Out
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- name: Set Up Java
uses: graalvm/setup-graalvm@v1
- uses: graalvm/setup-graalvm@v1
with:
version: ${{ inputs.version }}
distribution: ${{ inputs.distribution }}
java-version: ${{ inputs.java }}
cache: gradle

- name: Build Project
run: ./gradlew --stacktrace build
- run: ./gradlew --stacktrace build

- name: Build Site
run: ./gradlew --stacktrace -x build buildSite
- run: ./gradlew --stacktrace -x build buildSite

- name: Check Build
if: ${{ inputs.check_directory != '' }}
- if: ${{ inputs.check_directory != '' }}
run: ls -AlF "${{ inputs.check_directory }}"
6 changes: 4 additions & 2 deletions http/http_handlers/api/http_handlers.api
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public final class com/hexagonkt/http/handlers/HttpContext : com/hexagonkt/handl
public fun equals (Ljava/lang/Object;)Z
public final fun forbidden (Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun forbidden$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun found (Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun found$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun getAccept ()Ljava/util/List;
public fun getAttributes ()Ljava/util/Map;
public final fun getAuthorization ()Lcom/hexagonkt/http/model/Authorization;
Expand Down Expand Up @@ -234,8 +236,8 @@ public final class com/hexagonkt/http/handlers/HttpContext : com/hexagonkt/handl
public static synthetic fun notFound$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun ok (Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun ok$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun redirect (Lcom/hexagonkt/http/model/HttpStatus;Ljava/net/URI;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun redirect$default (Lcom/hexagonkt/http/handlers/HttpContext;Lcom/hexagonkt/http/model/HttpStatus;Ljava/net/URI;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun redirect (Lcom/hexagonkt/http/model/HttpStatus;Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun redirect$default (Lcom/hexagonkt/http/handlers/HttpContext;Lcom/hexagonkt/http/model/HttpStatus;Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun request (Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun request$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun send (Lcom/hexagonkt/http/model/HttpRequestPort;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.hexagonkt.http.model.*
import com.hexagonkt.http.model.INTERNAL_SERVER_ERROR_500
import com.hexagonkt.http.model.ServerEvent
import com.hexagonkt.http.model.ws.WsSession
import java.net.URI
import java.net.URL
import java.security.cert.X509Certificate
import java.util.concurrent.Flow.Publisher
Expand Down Expand Up @@ -204,7 +203,7 @@ data class HttpContext(

fun redirect(
status: HttpStatus,
location: URI,
location: String,
headers: Headers = response.headers,
cookies: List<Cookie> = response.cookies,
attributes: Map<*, *> = this.attributes,
Expand All @@ -216,6 +215,14 @@ data class HttpContext(
attributes = attributes
)

fun found(
location: String,
headers: Headers = response.headers,
cookies: List<Cookie> = response.cookies,
attributes: Map<*, *> = this.attributes,
): HttpContext =
redirect(FOUND_302, location, headers, cookies, attributes)

fun accepted(
onConnect: WsSession.() -> Unit = {},
onBinary: WsSession.(data: ByteArray) -> Unit = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.hexagonkt.serialization.serialize
import org.junit.jupiter.api.*

import java.math.BigInteger
import java.net.URI
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
Expand Down Expand Up @@ -90,7 +89,7 @@ abstract class ClientTest(
@Test open fun `Redirects are handled correctly correctly`() {
callback = {
if (queryParameters["ok"] != null) ok("redirected")
else redirect(FOUND_302, URI("/foo?ok"))
else found("/foo?ok")
}

val response = client.get()
Expand Down
Loading

0 comments on commit b736a0e

Please sign in to comment.