Skip to content

Commit

Permalink
Readme typos
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoupland committed Sep 21, 2018
1 parent a6b116a commit ee2f61c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -299,9 +299,9 @@ invoked, and to use external configuration variables that you can set up with
the Fn tool, have a look at the [Function
Configuration](docs/FunctionConfiguration.md) tutorial.

### Handling HTTP requests
### Handling HTTP requests

If your function serves an HTTP trigger you may want to access HTTP details such as request or response headers or the HTTP status , checko ut [Accessing HTTP Information From Functions](docs/HTTPGatewayFunctions.md).
If your function serves an HTTP trigger you may want to access HTTP details such as request or response headers or the HTTP status , check out [Accessing HTTP Information From Functions](docs/HTTPGatewayFunctions.md).

### Input and output bindings

Expand Down
26 changes: 13 additions & 13 deletions docs/HTTPGatewayFunctions.md
@@ -1,35 +1,35 @@
# Accessing HTTP Information From Functions
# Accessing HTTP Information From Functions

Functions can be used to handle events, RPC calls or HTTP requests. When you are writing a function that handles an HTTP request you frequently need access to the HTTP headers of the incoming request or need to set HTTP headers or the status code on the outbound respsonse.
Functions can be used to handle events, RPC calls or HTTP requests. When you are writing a function that handles an HTTP request you frequently need access to the HTTP headers of the incoming request or need to set HTTP headers or the status code on the outbound respsonse.


In Fn for Java, when your function is being served by an HTTP trigger (or another compatible HTTP gatway) you can get access to both the incoming request headers for your function by adding a 'com.fnproject.fn.api.httpgateway.HTTPGatewayContext' parameter to your function's parameters.
In Fn for Java, when your function is being served by an HTTP trigger (or another compatible HTTP gateway) you can get access to both the incoming request headers for your function by adding a 'com.fnproject.fn.api.httpgateway.HTTPGatewayContext' parameter to your function's parameters.


Using this allows you to :


Using this allows you to :

* Read incoming headers
* Access the method and request URL for the trigger
* Write outbound headers to the response
* Write outbound headers to the response
* Set the status code of the response


For example this function reads a request header the method and request URL, sets an response header and sets the response status code to perform an HTTP redirect.

```java
package com.fnproject.fn.examples;
import com.fnproject.fn.api.httpgateway.HTTPGatewayContext;


public class RedirectFunction {

public redirect(HTTPGatewayContext hctx) {
System.err.println("Request URL is:" + hctx.getRequestURL());
System.err.println("Trace ID" + hctx.getHeaders().get("My-Trace-ID").orElse("N/A"));

hctx.setResponseHeader("Location","http://example.com");
hctx.setStatusCode(302);

}
}

Expand Down

0 comments on commit ee2f61c

Please sign in to comment.