Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java11 template: Response Status Code can't be changed #225

Open
fakoe opened this issue Oct 22, 2020 · 0 comments
Open

Java11 template: Response Status Code can't be changed #225

fakoe opened this issue Oct 22, 2020 · 0 comments

Comments

@fakoe
Copy link

fakoe commented Oct 22, 2020

Expected Behaviour

Changing the status code of the response with res.setStatusCode(212) (similar to res.setBody()) should be possible.

Current Behaviour

Changing the status code doesn't change the response's status code. No matter what code is set, the java11 template always responds with "200".

Possible Solution

Wrong handling of the Status Code?

Steps to Reproduce (for bugs)

  1. Create java11 template
  2. Add line to Handler.java code: res.setStatusCode(202) or whatever number
  3. Build, push deploy java11 template
  4. Invoke or curl java11 function
  5. Get wireshark, or any other network sniffer and trace down the network traffic between openfaas and your pc

Context

I need custom status codes for http communication and I'm not able to set them properly.

I troubleshot the deployment (on Openshift) with using the write_debug: true setting in the .yaml-file.
This is the log of my deployment:

2020/10/22 10:07:48 Started logging stderr from function.
2020/10/22 10:07:48 Started logging stdout from function.
2020/10/22 10:07:48 OperationalMode: http
2020/10/22 10:07:48 Timeouts: read: 10s, write: 10s hard: 10s.
2020/10/22 10:07:48 Listening on port: 8080
2020/10/22 10:07:48 Writing lock-file to: /tmp/.lock
2020/10/22 10:07:48 Metrics listening on port: 8081
2020/10/22 10:08:01 POST /function/java11 - 212  - ContentLength: 35
2020/10/22 10:08:01 stdout: Request / 35 bytes written.

As you can see, the code is set properly there (from 200 to 212).
The problem is, when I log the network traffic between my client, which sends the curl (or invokes the function through the UI), this is the HTTP stream output (taken from wireshark):

GET /function/java11 HTTP/1.1
Host: <openfaas-ip>:8080
User-Agent: curl/7.61.1
Accept: */*

HTTP/1.1 200 OK
Content-Length: 35
Content-Type: text/plain; charset=utf-8
Date: Thu, 22 Oct 2020 11:03:07 GMT
X-Call-Id: 5fee7f67-3fd0-4262-9964-7bfd94a834c3
X-Duration-Seconds: 0.001307
X-Start-Time: 1603364587360704624

Hello, world! abcdefghijklmno

I guess the res.setStatusCode() is overwritten by the default handling of HTTP requests?

The response status in the UI of openfaas (under http://:8080) is also always set to 200, no matter what status code i set. Am I doing something wrong?

Your Environment

  • Docker version docker version (e.g. Docker 17.0.05 ):
    Version: 19.03.8

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    oc v3.11.0+0cbc58b
    kubernetes v1.11.0+d4cacc0
    Running on Openshift cluster under project/namespace openfaas-fn (for my functions)

  • Operating System and version (e.g. Linux, Windows, MacOS):
    CentOS 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant