how to build a webserver with grpc which can deal with http1.1 request?

3,790 views
Skip to first unread message

lwmo...@gmail.com

unread,
May 12, 2015, 4:35:35 AM5/12/15
to grp...@googlegroups.com
hi:

Can the GRPC  service process HTTP1.1 request naturally? eg. a request from browser.   If not,  what can I do to support it? 

Or  is I'm using GRPC wrong? Is it not used for building a webserver?

Thanks very much~

Yugui

unread,
May 12, 2015, 9:57:37 AM5/12/15
to lwmo...@gmail.com, grp...@googlegroups.com
I'm not sure what you mean by "building webserver", but you can use grpc-gateway so that you can call gRPC methods with XMLHTTPRequest+JSON.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/d1a0feb8-db01-44dc-b11d-258aa4973ee3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Anderson

unread,
May 12, 2015, 10:24:14 AM5/12/15
to lwmo...@gmail.com, grpc-io


On May 12, 2015 1:35 AM, <lwmo...@gmail.com> wrote:
> Can the GRPC  service process HTTP1.1 request naturally?

This is possible but not supported by any of the implementations currently.

> eg. a request from browser.   If not,  what can I do to support it?

This is not generally possible since gRPC requires trailer support and browser APIs don't support trailers. Some new APIs are being added to browsers that may support trailers, so it may be possible in the future to use gRPC natively on the browser.

grpc-gateway is a possible solution though.

Message has been deleted

lwmo...@gmail.com

unread,
May 13, 2015, 2:17:42 AM5/13/15
to grp...@googlegroups.com, lwmo...@gmail.com

I mean, we have some server which communicate to each other with HTTP1.1, if I build a new server with GRPC, can it communicate with the old ones?  

My requirement seems same with RESTful style... 

grpc-gateway is GREAT!  But when will you support for C++  ~~    haha
 

在 2015年5月12日星期二 UTC+8下午9:57:37,Yugui Sonoda写道:

lwmo...@gmail.com

unread,
May 13, 2015, 2:24:18 AM5/13/15
to grp...@googlegroups.com, lwmo...@gmail.com
Ignore the browser thing,  if I send a HTTP POST request (eg. use python urllib)  to a GRPC server,  can it process it?  If yes, is there any example?  

Thank you very much ~ ~~~~ 

在 2015年5月12日星期二 UTC+8下午10:24:14,Eric Anderson写道:

Nicolas Noble

unread,
May 13, 2015, 3:10:33 AM5/13/15
to lwmo...@gmail.com, grp...@googlegroups.com

The gateway can be used in front of any server. You don't need to write your server in go. Think of it as a reverse proxy process between your webserver backend and front-end.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.

lwmo...@gmail.com

unread,
May 13, 2015, 3:10:48 AM5/13/15
to grp...@googlegroups.com, lwmo...@gmail.com
It seems your grpc-gateway generate a reverse-proxy that is independent with the GRPC-server,  and it can be deployed to a different machine, is that true? 




在 2015年5月12日星期二 UTC+8下午9:57:37,Yugui Sonoda写道:

Yugui

unread,
May 13, 2015, 3:12:25 AM5/13/15
to lwmo...@gmail.com, grp...@googlegroups.com
Yes. It can be independently deployed wherever you want.
Also it is an independent process, so the implementation of grpc-gateway does not restrict the language in which you implement your service.

lwmo...@gmail.com

unread,
May 13, 2015, 9:57:43 PM5/13/15
to grp...@googlegroups.com, lwmo...@gmail.com
Clear,  thank you very much ~~ 

在 2015年5月13日星期三 UTC+8下午3:12:25,Yugui Sonoda写道:

lwmo...@gmail.com

unread,
May 13, 2015, 9:59:23 PM5/13/15
to grp...@googlegroups.com, lwmo...@gmail.com
Clear,  thank you very much ~~ 

在 2015年5月13日星期三 UTC+8下午3:10:33,Nicolas Noble写道:

bra...@ifup.co

unread,
May 17, 2015, 2:58:57 AM5/17/15
to grp...@googlegroups.com, lwmo...@gmail.com, Xiang Li, Brad Fitzpatrick, T...@eagain.net
On Tuesday, May 12, 2015 at 7:24:14 AM UTC-7, Eric Anderson wrote:


On May 12, 2015 1:35 AM, <lwmo...@gmail.com> wrote:
> Can the GRPC  service process HTTP1.1 request naturally?

This is possible but not supported by any of the implementations currently.

Is there a specification describing the right way to do this? We are discussing the issue for the Go bindings but we don't know what the specified way to support it is:


Thank You,

Brandon

Wolfgang Grieskamp

unread,
May 17, 2015, 12:20:41 PM5/17/15
to bra...@ifup.co, grpc-io, lwmo...@gmail.com, Xiang Li, Brad Fitzpatrick, T...@eagain.net
This may not be exactly what you are looking for, but there is a spec how to map proto rpcs (and hence grpc) to HTTP JSON REST here. It is based on annotations of the proto. The grpc-gateway discussion here sheds some more light on this.

Google is using that spec to expose a dual HTTP JSON REST/RPC entry point for APIs via proxy, there are tentative plans to open source the related technologies, but nothing firm yet.



-- 
Wolfgang

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.

xian...@coreos.com

unread,
May 17, 2015, 2:40:04 PM5/17/15
to grp...@googlegroups.com, xian...@coreos.com, lwmo...@gmail.com, brad...@google.com, bra...@ifup.co, T...@eagain.net
Actually, we want to use gRPC on the same port along with the HTTP 1.1 REST API. Then user can upgrade to use gRPC seamlessly. 
A proxy is not the ideal solution in this case.


This seems to be a wide solution than a Go specific thing.

Do you think we should open a new thread to discuss about this? 

Eric Anderson

unread,
May 17, 2015, 6:06:22 PM5/17/15
to xian...@coreos.com, grpc-io, lwmo...@gmail.com, Brad Fitzpatrick, bra...@ifup.co, T...@eagain.net
On Sun, May 17, 2015 at 11:40 AM, <xian...@coreos.com> wrote:
Actually, we want to use gRPC on the same port along with the HTTP 1.1 REST API.

Most of the HTTP/2 gRPC spec would apply to HTTP/1.1. Primarily the RST_STREAM doesn't exist in HTTP/1, so it would become a connection close instead.

Then user can upgrade to use gRPC seamlessly. 
A proxy is not the ideal solution in this case.

A reverse proxy can still work well here, but is not "ideal." Not "bad," but not "ideal."


This seems to be a wide solution than a Go specific thing.

Sorta, but not really. I think it is mainly implementation-specific HTTP handling issues; not wire-protocol issues. gRPC is not a fundamentally special HTTP client or server. This is why a reverse proxy would have no trouble having mixed gRPC and "normal" HTTP traffic, independent of HTTP/1.1 or HTTP/2.

The problem is that gRPC is an advanced HTTP user and goes through a lot of effort to be efficient. Lots of HTTP API don't support trailers, efficient flow control (no thread blocking), cheap streams (no thread-per-stream model), and full duplex (send and receive at same time), which are all HTTP/1.1 things to some degree.

In Java, I'm expecting us to eventually be able to run as just a Netty handler and do path-based dispatching, similar to ServeMux in Go. I'm heavily redesigning the Netty HTTP/2 API to do that though, and we don't yet know the performance cost.

Doing something similar in Go seems very feasible (without the redesign), but there are lots of details, and the performance impact is hard for me to predict.

For the other languages though, all of this is probably out-of-scope for the foreseeable future. In the mean time (even for Java and Go), using a reverse proxy seems like a more-immediate approach.

Adrià Casajús

unread,
May 18, 2015, 8:34:52 AM5/18/15
to grp...@googlegroups.com, lwmo...@gmail.com, T...@eagain.net, xian...@coreos.com, brad...@google.com, bra...@ifup.co
I don't think it's needed to implement HTTP/1.1. Just plain HTTP/2. Afaik there's a required header (Content-Type if I remember correctly) for gRPC calls. Can the server have a default handler for HTTP/2 streams that do not provide that required header?

Cheers,
 Adri

Eric Anderson

unread,
May 18, 2015, 11:48:03 AM5/18/15
to Adrià Casajús, grpc-io, lwmo...@gmail.com, Tommi Virtanen, Xiang Li, Brad Fitzpatrick, bra...@ifup.co
On Mon, May 18, 2015 at 5:34 AM, Adrià Casajús <ad...@ecm.ub.edu> wrote:
I don't think it's needed to implement HTTP/1.1. Just plain HTTP/2. Afaik there's a required header (Content-Type if I remember correctly) for gRPC calls. Can the server have a default handler for HTTP/2 streams that do not provide that required header?

Content-Type is a required header, and it is the primary way of ensuring that the client and server are both talking gRPC. However, to properly implement HTTP you should do path-based dispatching, because returning 404 must be independent of the Content-Type.

xian...@coreos.com

unread,
May 18, 2015, 11:53:43 AM5/18/15
to grp...@googlegroups.com, lwmo...@gmail.com, bra...@ifup.co, T...@eagain.net, brad...@google.com, xian...@coreos.com


On Sunday, May 17, 2015 at 3:06:22 PM UTC-7, Eric Anderson wrote:
On Sun, May 17, 2015 at 11:40 AM, <xian...@coreos.com> wrote:
Actually, we want to use gRPC on the same port along with the HTTP 1.1 REST API.

Most of the HTTP/2 gRPC spec would apply to HTTP/1.1. Primarily the RST_STREAM doesn't exist in HTTP/1, so it would become a connection close instead.

Then user can upgrade to use gRPC seamlessly. 
A proxy is not the ideal solution in this case.

A reverse proxy can still work well here, but is not "ideal." Not "bad," but not "ideal."


This seems to be a wide solution than a Go specific thing.

Sorta, but not really. I think it is mainly implementation-specific HTTP handling issues; not wire-protocol issues. gRPC is not a fundamentally special HTTP client or server. This is why a reverse proxy would have no trouble having mixed gRPC and "normal" HTTP traffic, independent of HTTP/1.1 or HTTP/2.

The problem is that gRPC is an advanced HTTP user and goes through a lot of effort to be efficient. Lots of HTTP API don't support trailers, efficient flow control (no thread blocking), cheap streams (no thread-per-stream model), and full duplex (send and receive at same time), which are all HTTP/1.1 things to some degree.

In Java, I'm expecting us to eventually be able to run as just a Netty handler and do path-based dispatching, similar to ServeMux in Go. I'm heavily redesigning the Netty HTTP/2 API to do that though, and we don't yet know the performance cost.

I can image there are two issues here: 
1. determine HTTP version 
2. if it is HTTP2, then we need to determine plain HTTP2 or gRPC over HTTP2.

Are you suggesting to use path-based dispatching to solve 2? 

Thanks!

Eric Anderson

unread,
May 18, 2015, 12:43:48 PM5/18/15
to Xiang Li, grpc-io, lwmo...@gmail.com, bra...@ifup.co, Tommi Virtanen, Brad Fitzpatrick
On Mon, May 18, 2015 at 8:53 AM, <xian...@coreos.com> wrote:

This seems to be a wide solution than a Go specific thing.

Sorta, but not really. I think it is mainly implementation-specific HTTP handling issues; not wire-protocol issues. gRPC is not a fundamentally special HTTP client or server. This is why a reverse proxy would have no trouble having mixed gRPC and "normal" HTTP traffic, independent of HTTP/1.1 or HTTP/2.

The problem is that gRPC is an advanced HTTP user and goes through a lot of effort to be efficient. Lots of HTTP API don't support trailers, efficient flow control (no thread blocking), cheap streams (no thread-per-stream model), and full duplex (send and receive at same time), which are all HTTP/1.1 things to some degree.

In Java, I'm expecting us to eventually be able to run as just a Netty handler and do path-based dispatching, similar to ServeMux in Go. I'm heavily redesigning the Netty HTTP/2 API to do that though, and we don't yet know the performance cost.

I can image there are two issues here: 
1. determine HTTP version 
2. if it is HTTP2, then we need to determine plain HTTP2 or gRPC over HTTP2.

Are you suggesting to use path-based dispatching to solve 2?

Yes. "gRPC over HTTP2" is very similar to "REST over HTTP2" or "web application over HTTP2" from a dispatching perspective.

If the API is mostly agnostic to HTTP version, then step 1 may not be necessary. From what I can tell, all the HTTP/2 specific stuff on server-side would be handled by a reasonable higher-level HTTP/2 server library normally or doesn't matter much on server-side.

shrivin...@gmail.com

unread,
Apr 19, 2018, 3:17:13 AM4/19/18
to grpc.io
Hi Liang,

Were you able to write the gRPC server in C++ which can talk via grpc-gateway which will get HTTP message from another web application 

shrivin...@gmail.com

unread,
Apr 19, 2018, 3:20:51 AM4/19/18
to grpc.io
Any example with C++ you know of will be very helpful.
Reply all
Reply to author
Forward
0 new messages