-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): allow setting response headers
The Netty response intrinsic provided to guests is missing a method to set headers on the response. While we're there, I can add some other methods users may need. - fix: header methods on response intrinsic - chore: re-pin `graalvm` module - chore: update `graalvm` detekt baseline - chore: more gitattribute fixes Signed-off-by: Sam Gammon <sam@elide.ventures>
- Loading branch information
Showing
7 changed files
with
279 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/graalvm/src/main/kotlin/elide/runtime/intrinsics/server/http/ExpressResponseAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2024 Elide Technologies, Inc. | ||
* | ||
* Licensed under the MIT license (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/license/mit/ | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
package elide.runtime.intrinsics.server.http | ||
|
||
import elide.annotations.API | ||
import elide.runtime.core.DelicateElideApi | ||
import elide.runtime.core.PolyglotValue | ||
import elide.vm.annotations.Polyglot | ||
|
||
/** | ||
* # Express Response API | ||
* | ||
* Defines methods available on an Express `Response` object; these are mixed into the standard [HttpResponse] so that | ||
* guests may specify responses using this API. | ||
*/ | ||
@API @DelicateElideApi public interface ExpressResponseAPI { | ||
/** | ||
* Exported method allowing guest code to set the response [status] code. | ||
* | ||
* This method is not terminal, unlike [send]. | ||
* | ||
* @param status The HTTP status code to send. | ||
*/ | ||
@Polyglot public fun status(status: Int) | ||
|
||
/** | ||
* Exported method allowing guest code to end the request/response cycle; equivalent to calling [send]. | ||
* | ||
* This method is terminal. | ||
*/ | ||
@Polyglot public fun end() | ||
|
||
/** | ||
* Exported method allowing guest code to send a response to the client with the given [status] code and [body]. | ||
* | ||
* @param status The HTTP status code to send. | ||
* @param body The body of the response to send. | ||
*/ | ||
@Polyglot public fun send(status: Int, body: PolyglotValue?) | ||
|
||
/** | ||
* Get a header from the response; this method is exported to guest code. | ||
* | ||
* @param name The name of the header to set. | ||
*/ | ||
@Polyglot public fun get(name: String): String? | ||
|
||
/** | ||
* Set a header to the response; this method is exported to guest code. | ||
* | ||
* Note that headers must be provided before [send] is called. | ||
* This method will set a header to the response, overwriting any existing header(s) by the same name. | ||
* | ||
* @param name The name of the header to set. | ||
* @param value The value of the header to set. | ||
*/ | ||
@Polyglot public fun set(name: String, value: String? = null) | ||
|
||
/** | ||
* Append a header to the response; this method is exported to guest code. | ||
* | ||
* Note that headers must be provided before [send] is called. | ||
* This method will add a header to the response even if there is already a header by the same name. | ||
* | ||
* @param name The name of the header to set. | ||
* @param value The value of the header to set. | ||
*/ | ||
@Polyglot public fun append(name: String, value: String? = null) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters