socket-based HTTP server

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

socket-based HTTP server

Marco Lazzaroni
Hi all,
sorry for such a basic question. I've developed an application based on the raw API, then I had to integrate an RTOS and I had to switch to a socket based API.
To my understanding, the raw API based http server is run by code in lwip/src/apps/http/httpd.c.
For the socket API, I started from lwip/contrib/apps/httpserver/httpserver-netconn.c and I wrote httpserver-socket.c making some obvious changes.
Well, it works and it's quite stable, but now I need to implement CGI / SSI functionality in order to show the value of some variables.  I also need to import HTTP POST functionality that already worked with the raw API.
I suppose that the code in httpd.c is not directly usable because it is for the raw API (correct?).
I'm starting porting it to socket version by hand; i.e. I'm taking some pieces of http_parse_request() in order to parse the HTTP request, to get the URI, the HTTP/1.1 (or 0.9) string and so on.
Anyway I'm asking myself if I have searched enough: is there something I can reuse for my purposes in the lwip tree? Or even outside it, being the socket API a standard, is there something reusable for an embedded web server?
Thank you for your help.
Best regards,
  Marco

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: socket-based HTTP server

goldsimon@gmx.de
Am 01.04.2020 um 09:40 schrieb Marco Lazzaroni:
> Hi all,
> sorry for such a basic question. I've developed an application based on
> the raw API, then I had to integrate an RTOS and I had to switch to a
> socket based API.

You can continue using the callback API when using an OS, you just have
to make sure you only call into lwIP core functions from tcpip_thread or
surrounded by LOCK_TCPIP_CORE()/UNLOCK_TCPIP_CORE().

> To my understanding, the raw API based http server is run by code in
> lwip/src/apps/http/httpd.c.
> For the socket API, I started from
> lwip/contrib/apps/httpserver/httpserver-netconn.c and I wrote
> httpserver-socket.c making some obvious changes.

httpserver-netconn.c has *nothing* to do with the callback version
(httpd.c).

> Well, it works and it's quite stable, but now I need to implement CGI /
> SSI functionality in order to show the value of some variables.  I also
> need to import HTTP POST functionality that already worked with the raw API.
> I suppose that the code in httpd.c is not directly usable because it is
> for the raw API (correct?).
> I'm starting porting it to socket version by hand; i.e. I'm taking some
> pieces of http_parse_request() in order to parse the HTTP request, to
> get the URI, the HTTP/1.1 (or 0.9) string and so on.
> Anyway I'm asking myself if I have searched enough: is there something I
> can reuse for my purposes in the lwip tree? Or even outside it, being
> the socket API a standard, is there something reusable for an embedded
> web server?

There should be enough socket-based http servers in the net. That's why
we didn't invent yet another one.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: socket-based HTTP server

Marco Lazzaroni
Il giorno gio 2 apr 2020 alle ore 20:27 [hidden email] <[hidden email]> ha scritto:
Am 01.04.2020 um 09:40 schrieb Marco Lazzaroni:
> Hi all,
> sorry for such a basic question. I've developed an application based on
> the raw API, then I had to integrate an RTOS and I had to switch to a
> socket based API.

You can continue using the callback API when using an OS, you just have
to make sure you only call into lwIP core functions from tcpip_thread or
surrounded by LOCK_TCPIP_CORE()/UNLOCK_TCPIP_CORE().
Ok thank you, good news for me! I thought it was not possible to use both APIs at the same time.  In particular, I have integrated the mbedtls library in order to do a HTTPS notification from my application, but the web server will be a standard HTTP server as before. Obviously I have to look better in what you suggested and try to implement it.
 
> To my understanding, the raw API based http server is run by code in
> lwip/src/apps/http/httpd.c.
> For the socket API, I started from
> lwip/contrib/apps/httpserver/httpserver-netconn.c and I wrote
> httpserver-socket.c making some obvious changes.

httpserver-netconn.c has *nothing* to do with the callback version
(httpd.c).

> Well, it works and it's quite stable, but now I need to implement CGI /
> SSI functionality in order to show the value of some variables.  I also
> need to import HTTP POST functionality that already worked with the raw API.
> I suppose that the code in httpd.c is not directly usable because it is
> for the raw API (correct?).
> I'm starting porting it to socket version by hand; i.e. I'm taking some
> pieces of http_parse_request() in order to parse the HTTP request, to
> get the URI, the HTTP/1.1 (or 0.9) string and so on.
> Anyway I'm asking myself if I have searched enough: is there something I
> can reuse for my purposes in the lwip tree? Or even outside it, being
> the socket API a standard, is there something reusable for an embedded
> web server?

There should be enough socket-based http servers in the net. That's why
we didn't invent yet another one.

I agree! In the meanwhile I had worked at the socket version, now I was roughly at a third of the job, but it's better to save it somewhere and switch back to the callback API.
Thank you again!
Best regards,
  Marco

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: socket-based HTTP server

Marco Lazzaroni


Il giorno ven 3 apr 2020 alle ore 10:05 Marco Lazzaroni <[hidden email]> ha scritto:
Il giorno gio 2 apr 2020 alle ore 20:27 [hidden email] <[hidden email]> ha scritto:
Am 01.04.2020 um 09:40 schrieb Marco Lazzaroni:
> Hi all,
> sorry for such a basic question. I've developed an application based on
> the raw API, then I had to integrate an RTOS and I had to switch to a
> socket based API.

You can continue using the callback API when using an OS, you just have
to make sure you only call into lwIP core functions from tcpip_thread or
surrounded by LOCK_TCPIP_CORE()/UNLOCK_TCPIP_CORE().
Ok thank you, good news for me! I thought it was not possible to use both APIs at the same time.  In particular, I have integrated the mbedtls library in order to do a HTTPS notification from my application, but the web server will be a standard HTTP server as before. Obviously I have to look better in what you suggested and try to implement it.

It works and it is also much more efficient than before! Thank you again for your suggestion!
Cheers
 Marco 

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users