API access via HTTP protocol

We have a service, which is pushing data to Flash version of Origam via HTTP API on intranet network. The service cannot communicate via HTTPS. Is there a way to stop automatic redirect from HTTP to HTTPS for API requests in HTML5 version? See attached capture from Wireshark. If not it would be great to implement it for intranet usage via an option in appsettings.json.

What does your stack look like? Do you use HTML5 server directly or is there something in front of it (IIS, nginx)?

There is IIS stack with .net core 5.xx

IIS is responsible for the redirection. You can set up a separate instance that has only HTTP binding.

I set a separate instance only with HTTP bindings. Now I can push the request from browser but when I push it from the GPS proxy service I get error 500. Both requests look the same. See attached image from Wireshark capture (I can share it). But there are several differences in the http parts - the GPS service request sets Content-Type: text , but the Origam API expects MIME text/html. Could wrong content-type generate IIS internal error 500?

image

I doubt IIS itself generates 500 response. I’d expect it from Origam server. There should be something in the log.

I foud in .net error log

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.FormatException: The header contains invalid values at index 0: 'text'
         at Microsoft.Net.Http.Headers.HttpHeaderParser`1.ParseValue(StringSegment value, Int32& index)
         at Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse(StringSegment input)
         at Origam.ServerCommon.Pages.StandardHttpRequestWrapper..ctor(HttpContext httpContext) in D:\a\1\s\origam-source\Origam.ServerCommon\Pages\StandardHttpRequestWrapper.cs:line 51
         at Origam.ServerCommon.Pages.StandardHttpContextWrapper..ctor(HttpContext context) in D:\a\1\s\origam-source\Origam.ServerCommon\Pages\StandardHttpContextWrapper.cs:line 34
         at Origam.ServerCore.Middleware.UserApiMiddleWare.Invoke(HttpContext context) in D:\a\1\s\origam-source\Origam.ServerCore\Middleware\UserApiMiddleWare.cs:line 38
         at Microsoft.AspNetCore.Buffering.ResponseBufferingMiddleware.Invoke(HttpContext httpContext)
         at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
         at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
         at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

I see. I’d argue then that the service doesn’t send valid MIME type (MIME types (IANA media types) - HTTP | MDN). The request is stopped before reaching Origam code responsible for resolving, which API is going to be used. I’d recommend to change the content type sent by the service to text/plain.

Thank you for your analysis. I’ve to contact the GPS service creator - @urbanekv and @tvavrda to update the service behavior.

What about trying to use a rewrite rule in order to set the right header? That way we could do it without changing the mentioned service.

Are you sure you can modify header on inbound request with IIS rewrite module? I can find header modification examples only on outbound responses.

You can use server variable CONTENT_TYPE, I guess.

What you can try is also to register your own content type in IIS?

I tried the IIS rewrite module with ARR, but with no success. I can rewrite the CONTENT_TYPE variable, but there is the same error on Origam side. I think, it would be better to repair the source code of the GPS service, so it uses correct MIME type.

Rewrite rule trace:

Origam logging:

2021-07-27 14:33:56,663 [23] INFO Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/1.1 GET http://10.10.10.252:8080/api/public/setLocation?imei=359710044448042&latitude=50.127475&longitude=15.393025&azimuth=0&speed=0.00 text -
2021-07-27 14:33:56,664 [23] TRACE Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware - All hosts are allowed.
2021-07-27 14:33:56,664 [23] DEBUG Microsoft.AspNetCore.HttpsPolicy.HstsMiddleware - The request is insecure. Skipping HSTS header.
2021-07-27 14:33:56,664 [23] DEBUG Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler - AuthenticationScheme: Identity.Application was not authenticated.
2021-07-27 14:33:56,664 [23] DEBUG Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler - AuthenticationScheme: Identity.Application was not authenticated.
2021-07-27 14:33:56,681 [23] ERROR Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware - An unhandled exception has occurred while executing the request.
System.FormatException: The header contains invalid values at index 0: 'text'
   at Microsoft.Net.Http.Headers.HttpHeaderParser`1.ParseValue(StringSegment value, Int32& index)
   at Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse(StringSegment input)
   at Origam.ServerCommon.Pages.StandardHttpRequestWrapper..ctor(HttpContext httpContext) in D:\a\1\s\origam-source\Origam.ServerCommon\Pages\StandardHttpRequestWrapper.cs:line 51
   at Origam.ServerCommon.Pages.StandardHttpContextWrapper..ctor(HttpContext context) in D:\a\1\s\origam-source\Origam.ServerCommon\Pages\StandardHttpContextWrapper.cs:line 34
   at Origam.ServerCore.Middleware.UserApiMiddleWare.Invoke(HttpContext context) in D:\a\1\s\origam-source\Origam.ServerCore\Middleware\UserApiMiddleWare.cs:line 38
   at Microsoft.AspNetCore.Buffering.ResponseBufferingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
   at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.HttpsPolicy.HstsMiddleware - The request is insecure. Skipping HSTS header.
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler - AuthenticationScheme: Identity.Application was not authenticated.
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler - AuthenticationScheme: Identity.Application was not authenticated.
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler - AuthenticationScheme: Identity.Application was not authenticated.
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware - The request path  does not match the path filter
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware - The request path  does not match the path filter
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware - The request path /Error/Error does not match a supported file type
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Routing.RouteBase - Request successfully matched the route with name 'default' and template '{controller}/{action=Index}/{id?}'
2021-07-27 14:33:56,682 [23] INFO Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Route matched with {action = "Error", controller = "Error"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Error() on controller Origam.ServerCore.IdentityServerGui.Account.ErrorController (Origam.ServerCore).
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Execution plan of authorization filters (in the following order): None
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Execution plan of resource filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Execution plan of action filters (in the following order): Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter (Order: -2147483648), Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter (Order: -3000)
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Execution plan of exception filters (in the following order): None
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Execution plan of result filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Resource Filter: Before executing OnResourceExecuting on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Resource Filter: After executing OnResourceExecuting on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Executing controller factory for controller Origam.ServerCore.IdentityServerGui.Account.ErrorController (Origam.ServerCore)
2021-07-27 14:33:56,682 [23] DEBUG Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Executed controller factory for controller Origam.ServerCore.IdentityServerGui.Account.ErrorController (Origam.ServerCore)
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Action Filter: Before executing OnActionExecutionAsync on filter Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Action Filter: After executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2021-07-27 14:33:56,682 [23] INFO Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Executing action method Origam.ServerCore.IdentityServerGui.Account.ErrorController.Error (Origam.ServerCore) - Validation state: Valid
2021-07-27 14:33:56,682 [23] INFO Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Executed action method Origam.ServerCore.IdentityServerGui.Account.ErrorController.Error (Origam.ServerCore), returned result Microsoft.AspNetCore.Mvc.ViewResult in 0.008ms.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Action Filter: Before executing OnActionExecuted on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Action Filter: After executing OnActionExecuted on filter Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Action Filter: After executing OnActionExecutionAsync on filter Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Result Filter: Before executing OnResultExecuting on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Result Filter: After executing OnResultExecuting on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,682 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Before executing action result Microsoft.AspNetCore.Mvc.ViewResult.
2021-07-27 14:33:56,683 [23] DEBUG Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine - View lookup cache hit for view 'Error' in controller 'Error'.
2021-07-27 14:33:56,683 [23] INFO Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor - Executing ViewResult, running view Error.
2021-07-27 14:33:56,683 [23] DEBUG Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor - The view path '/Views/Shared/Error.cshtml' was found in 0.0829ms.
2021-07-27 14:33:56,683 [23] DEBUG Microsoft.Extensions.Localization.ResourceManagerStringLocalizer - ResourceManagerStringLocalizer searched for 'UnknownError' in 'Origam.ServerCore.Resources.SharedResources' with culture 'cs-CZ'.
2021-07-27 14:33:56,683 [23] DEBUG Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine - View lookup cache hit for view '_Layout' in controller 'Error'.
2021-07-27 14:33:56,683 [23] DEBUG Microsoft.Extensions.Localization.ResourceManagerStringLocalizer - ResourceManagerStringLocalizer searched for 'IdentityServerTitle' in 'Origam.ServerCore.Resources.SharedResources' with culture 'cs-CZ'.
2021-07-27 14:33:56,684 [23] INFO Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor - Executed ViewResult - view Error executed in 0.6099ms.
2021-07-27 14:33:56,684 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - After executing action result Microsoft.AspNetCore.Mvc.ViewResult.
2021-07-27 14:33:56,684 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Result Filter: Before executing OnResultExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,684 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Result Filter: After executing OnResultExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,684 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Resource Filter: Before executing OnResourceExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,684 [23] TRACE Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Resource Filter: After executing OnResourceExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter.
2021-07-27 14:33:56,684 [23] INFO Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker - Executed action Origam.ServerCore.IdentityServerGui.Account.ErrorController.Error (Origam.ServerCore) in 1.5615ms