mscholtes / webserver Goto Github PK
View Code? Open in Web Editor NEWPowershell WebServer is a Powershell module that starts a webserver (without the need for IIS)
License: Other
Powershell WebServer is a Powershell module that starts a webserver (without the need for IIS)
License: Other
I can download smaller files (in megabytes) but not for bigger files /tested with 2.3GB and others
On the logs I see:
try {
$BUFFER = [System.IO.File]::ReadAllBytes($CHECKFILE)
$RESPONSE.ContentLength64 = $BUFFER.Length
$RESPONSE.SendChunked = $FALSE
if ($MIMEHASH.ContainsKey($EXTENSION))
{ # known mime type for this file's extension available
$RESPONSE.ContentType = $MIMEHASH.Item($EXTENSION)
}
else
{ # no, serve as binary download
$RESPONSE.ContentType = "application/octet-stream"
$FILENAME = Split-Path -Leaf $CHECKFILE
$RESPONSE.AddHeader("Content-Disposition", "attachment; filename=$FILENAME")
}
$RESPONSE.AddHeader("Last-Modified", [IO.File]::GetLastWriteTime($CHECKFILE).ToString('r'))
$RESPONSE.AddHeader("Server", "Powershell Webserver/1.5 on ")
$RESPONSE.OutputStream.Write($BUFFER, 0, $BUFFER.Length)
# mark response as already given
$RESPONSEWRITTEN = $TRUE
}
catch
{
# just ignore. Error handling comes afterwards since not every error throws an exception
}
if ($Error.Count -gt 0)
{ # retrieve error message on error
$RESULT = "`nError while downloading '$CHECKFILE'`n`n"
$RESULT += $Error[0]
$Error.Clear()
}
Severity Code Description Project File Line Suppression State
Error Could not install package 'WebServer 1.0.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
How can I list all the files hosted on the PowerShell based webserver?
Using regex would be easier to parse PSP files. I did not test complex files but your example works perfect.
$psp = @'
<%Param($first,$second)%>
<!doctype html>
<html>
<head>
<title>Powershell Server Pages (PSP) demo</title>
<meta charset="utf-8">
</head>
<body>
<H3>Powershell Server Pages (PSP) demo</H3>
<hr />
Hello <% = $first %>,
<%
Write-Output "<br />"
Write-Output $second
%>
<hr />
</body>
</html>
'@
[regex]::matches($psp,'<%([^%]+)%>','IgnorePatternWhitespace,Multiline')
Groups : {0, 1}
Success : True
Name : 0
Captures : {0}
Index : 0
Length : 25
Value : <%Param($first,$second)%>
Groups : {0, 1}
Success : True
Name : 0
Captures : {0}
Index : 224
Length : 14
Value : <% = $first %>
Groups : {0, 1}
Success : True
Name : 0
Captures : {0}
Index : 241
Length : 51
Value : <%
Write-Output "<br />"
Write-Output $second
%>
Hi @MScholtes,
I am coding with PSP files, and I can't see errors in the web-browser nor in the terminal.
Is it possible to enable error showing?
+=
operator with strings (and arrays) results in memory leakage. Better try list
or stringbuilder
types.Hi @MScholtes
That is a great tool.
I have two questions,
As first feature statement said, what is execution and command web form?
And webserver accept post, and how to handle json(json array) body payload inside psp file.
Thanks
Eric Xin
.mjs is the extension used for ES6 javascript modules. Modules use strict mime typing, so won't load when application/octet-stream is returned
$LISTENER.Prefixes.Add($BINDING)
method requeres a trailing "/" in URL.
Exception calling "Add" with "1" argument(s): "Only Uri prefixes ending in '/' are allowed.
Parameter name: uriPrefix"
$binding = $binding.trimend('/ ') + '/'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.