The MASM Forum

Projects => ObjAsm => Topic started by: Biterider on December 24, 2020, 07:21:54 PM

Title: HTTP Server
Post by: Biterider on December 24, 2020, 07:21:54 PM
Hi
To my surprise, MS released an "HTTP server API" a few years ago.
This simplifies the processing of http requests considerably.
The code is implemented in the kernel, is extremely stable and is also used by IIS.

The API is described here https://docs.microsoft.com/en-us/windows/win32/http/http-server-api-overview (https://docs.microsoft.com/en-us/windows/win32/http/http-server-api-overview).

Looking at the code examples, I've implemented the assembler version and tested it with a browser and Postman http://masm32.com/board/index.php?topic=8916.msg97371#msg97371 (http://masm32.com/board/index.php?topic=8916.msg97371#msg97371).

In the example, 2 verbs GET & POST are implemented. GET returns a greeting message and POST returns the same text that was sent in the body.
The code is simple and can be used for many purposes, such as online games, databases http://masm32.com/board/index.php?topic=8352.msg92037#msg92037 (http://masm32.com/board/index.php?topic=8352.msg92037#msg92037), IoT projects and custom applications.
A very convenient and flexible way to exchange data with a server is using JSON. An assembler implementation can be found here
http://masm32.com/board/index.php?topic=9001.0 (http://masm32.com/board/index.php?topic=9001.0).
For those who are concerned about security, the Server API also includes TLS/SSL https://de.wikipedia.org/wiki/Transport_Layer_Security

Attached is a working example and the necessary include file to build the project in 32/64 bit.
The included binary is compiled for 32 bit and ANSI strings.

Since you will likely want to test the code on your network, you will need administrative rights to register the URL to look for.
I've included the necessary resource to start with elevated privileges at the beginning of execution.
If you only want to work locally, these are not required.  :icon_idea:

I am very happy to see that we have all the building blocks in assembler and that we can realize very cool projects with ease.  :biggrin:
If you miss some file, please check the GitHub repository.

Regards, Biterider
Title: Re: HTTP Server
Post by: TouEnMasm on December 24, 2020, 08:37:11 PM
Hello,
With Administrator right,answer ; failed to register the server (windows 10)
https://docs.microsoft.com/en-us/windows/win32/http/http-server-sample-application (https://docs.microsoft.com/en-us/windows/win32/http/http-server-sample-application)
Title: Re: HTTP Server
Post by: jj2007 on December 24, 2020, 09:36:40 PM
I won't have the time and resources to test it, but hey, my compliments, you are doing remarkable stuff here :thumbsup:
Title: Re: HTTP Server
Post by: Biterider on December 24, 2020, 10:13:45 PM
Hi TouEnMasm
You admin account is missing some ACL for the registration.
Try using netsh.
The link you pointed to is the base I used for the assembler port. It is also mentioned in the header of the HttpServer.inc file along with other useful links.

Regards, Biterider
Title: Re: HTTP Server
Post by: Vortex on December 24, 2020, 11:57:02 PM
Hi Biterider,

Starting the application, I receive the error message :

Registration error!
Start DebugCenter manually...


OS : Windows 10 64-bit
Title: Re: HTTP Server
Post by: Biterider on December 25, 2020, 12:09:36 AM
Hi Vortex
I uploaded the debug version.  :rolleyes:
I recompiled the project for release and attached the new binary here.

Biterider
Title: Re: HTTP Server
Post by: TouEnMasm on December 25, 2020, 01:37:39 AM

The new binary seem to connect to the server but the help menu failed to connect to url.

I post the c++ sample of microsoft.He is a dos prog and wait for a parameter or two.
It seems also to have the same fault.
Title: Re: HTTP Server
Post by: Biterider on December 25, 2020, 03:18:08 AM
Hi
Glad you were able to connect to the server. The URL I used is http:\\<your IP>:8080

The help menu item "Help" shows the default pdf viewer on your system (if there is any defined) and displays the ObjAsm help file.
If you don't have a regular ObjAsm installation, nothing will be shown.

Biterider
Title: Re: HTTP Server
Post by: TouEnMasm on December 25, 2020, 03:25:04 AM
Ok ,the sample don't connect to any url and don't show an html page.
Searching the windows samples,i find this one:
There is two versions of http,who don't used the same functions.
The sample added give the url to use to connect in version 2
But he don't show how view an html page.
The missing piece of code is to be searched somewhere.

HAPPY CHRISTMAS
Title: Re: HTTP Server
Post by: Biterider on December 25, 2020, 03:40:27 AM
Hi
This code and the example from MS are not intended to display an HTML site.
It's all about plain HTTP/HTTPS.


Biterider


Title: Re: HTTP Server
Post by: fearless on May 26, 2022, 07:43:30 PM
Thanks for the example. I found this useful as I am trying to implement a webhook receiver for an emby media server. HttpServer is basically what I need, so good to know that someone has looked at this.
I put together some Radasm Masm Api files for ease of use, for x86 version for the moment. Just open each txt file and copy and paste the contents into the correct corresponding files: \Radasm\Masm\MasmApiCall.api, \Radasm\Masm\MasmApiConst.api and \Radasm\Masm\MasmApiStruct.api
Title: Re: HTTP Server
Post by: Biterider on May 26, 2022, 08:12:21 PM
Hi fearless
Thanks for the radasm api definition files.  :thumbsup:

Biterider