openfaas / nats-queue-worker

Queue-worker for OpenFaaS with NATS Streaming
https://docs.openfaas.com/reference/async/
MIT License
129 stars 59 forks source link

Propagate deserialized HTTP Host header to the function for asynchronous invocation #34

Closed dmrub closed 6 years ago

dmrub commented 6 years ago

This commit is related to the faas PR https://github.com/openfaas/faas/pull/816 Because faas queue.Request struct is modified this commit includes modification in the vendor directory.

Description

See PR https://github.com/openfaas/faas/pull/816 and issue https://github.com/openfaas-incubator/of-watchdog/issues/22

Motivation and Context

How Has This Been Tested?

Types of changes

Checklist:

alexellis commented 6 years ago

Just a quick question. How have you tested this?

dmrub commented 6 years ago

Yes, I tested it with deploy_stack.sh and then running curl and forwarding request to webserver which dumps all incoming requests:
curl -v -H "Host: blabla" -H "X-Callback-Url: http://192.168.1.5:8000" -X POST -d '{"key1":"value1", "key2":"value2"}' http://127.0.0.1:8080/async-function/hello-python

Web Server logged following:

/
Host: 192.168.1.5:8000
User-Agent: Go-http-client/1.1
Content-Length: 898
Content-Type: application/x-www-form-urlencoded
Date: Sat, 01 Sep 2018 18:29:49 GMT
X-Duration-Seconds: 0.058162
Accept-Encoding: gzip
Connection: close

Request: [
{"key1":"value1", "key2":"value2"}
]
HTTP Headers: [
Http_X_Callback_Url: http://192.168.1.5:8000
Http_X_Start_Time: 1535826589144404574
Http_Connection: close
Http_ContentLength: 34
Http_Method: POST
Http_X_Call_Id: 889ae659-9e56-4764-ad71-df771e55c8cf
Http_Content_Type: application/x-www-form-urlencoded
Http_Accept_Encoding: gzip
Http_Accept: */*
Http_User_Agent: curl/7.55.1
Http_Path: /
Http_Content_Length: 34
Http_Host: blabla
]

My hello-python.py:

from __future__ import print_function
import os
import sys

def handle(req):
    """handle a request to the function
    Args:
        req (str): request body
    """

    s = "Request: [\n"+req+"\n]\nHTTP Headers: [\n" \
        + '\n'.join([k + ': ' + v for k,v in os.environ.items() if k.startswith('Http_')]) \
        + '\n]\n'

    print(s, file=sys.stderr)

    return s
alexellis commented 6 years ago

SGTM :smile: Thanks for providing the detail.

alexellis commented 6 years ago

I've cut a release so this will be the new tag for the Docker image: https://github.com/openfaas/nats-queue-worker/releases/tag/0.5.0

Please can you bump up x86_64 versions in faas-netes (helm/charts + ./yaml) and faas (docker-compose)? cc @martindekov to review