I'm trying to parse a POST request using apache and mod_lua, i have something like this :
function authz_bulk_get(r, id_dash)
r:debug("BULK_DEBUG START")
if r.method == 'GET' then
for k, v in pairs(r:parseargs()) do
r:debug("BULK_DEBUG " .. k .. " " .. v)
end
elseif r.method == 'POST' then
r:debug("BULK_DEBUG TREAT POST")
local jv_content = r:requestbody()
r:debug("BULK_DEBUG REQUEST_BODY")
r:debug("BULK_DEBUG " .. jv_content)
jv_content = jv_content:gsub("%[", "")
jv_content = jv_content:gsub("%]", "")
local jv_jsonparse = json.decode(jv_content)
r:debug("BULK_DEBUG " .. jv_content)
r:debug("BULK_DEBUG " .. jv_jsonparse["type"])
r:debug("BULK_DEBUG " .. jv_jsonparse["id"])
end
r:debug("BULK_DEBUG END")
return apache2.AUTHZ_GRANTED
end
Everything seems OK in debug logs, i have all correct traces and I see requestbody and json parsing executing well but the response is {"statusCode":400,"error":"Bad Request","message":"[request body]: expected value of type [array] but got [null]"}
It looks like the request is emptied when i do r:requestbody()
Maybe I need to re-transmit the POST request after doing this processing ?
Any ideas ?
Thanks
Related
I am using devTools in selenium 4 to retrieve the responses from the network tab.
While I am getting the url, response code, headers etc,
I could not find a way to retrieve the actual response body. (My intention is to validate the key value pairs in the response.)
Any help is much appreciated.
Below is a snippet from my code.
devTools.addListener(Network.responseReceived(),
response -> {
Response res= response.getResponse();
System.out.println("URL - " + res.getUrl());
System.out.println("Status - " + res.getStatus());
System.out.println("Headers - " + res.getHeaders());
System.out.println("Header text - " + res.getHeadersText());
});
devTools = ((ChromeDriver) driver).getDevTools();
devTools.createSession();
devTools.send(Network.clearBrowserCache());
devTools.send(Network.setCacheDisabled(true));
final RequestId[] requestIds = new RequestId[1];
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.of(100000000)));
devTools.addListener(Network.responseReceived(), responseReceived -> {
requestIds[0] = responseReceived.getRequestId();
String url = responseReceived.getResponse().getUrl();
int status = responseReceived.getResponse().getStatus();
String type = responseReceived.getType().toJson();
String headers = responseReceived.getResponse().getHeaders().toString();
String responseBody = devTools.send(Network.getResponseBody(requestIds[0])).getBody();
This compiles in ReasonML:
let testFn = who => Js.(log("Hello " ++ who ++ "!"));
but not in ReScript:
FAILED: src/test.ast
Syntax error!
/xxx/src/test.res:1:25-27
1 │ let testFn = who => Js.(log("Hello " ++ who ++ "!"));
2 │
I'm not sure what to parse here when looking at "(".
Syntax error!
/xxx/src/test.res:1:25-27
1 │ let testFn = who => Js.(log("Hello " ++ who ++ "!"));
2 │
consecutive statements on a line must be separated by ';' or a newline
I didn't find any mention of removal in official docs. Did I miss it? Has syntax changed, or was it removed and not mentioned in docs?
As pointed out by #Yawar in the comments, this short-hand is not supported at time of writing, but is likely to be at some point in the future (see https://github.com/rescript-lang/syntax/issues/2 for discussion).
And just to save a click for those coming across this, a workaround is to rewrite it using a local scope and opening the module in that scope:
let testFn = who => {
open Js
log("Hello " ++ who ++ "!")
}
I want to process and verify that PDFs within a folder are valid PDF/A files. The problem is that I need to process a folder with piles of files including word and excel among others that preflight converts to PDFs, processes, and then hangs for user input to discard the temperary file. There are some hundred files, so waiting for user input isn't doable.
Perhaps I'm not using the correct phrases when I search, but I can't find out how to force Adobe Acrobat DC to only process PDF files. I've found that in Acrobat X you can specify source files https://www.evermap.com/ActionWizardX.asp, but I've not found an equivalent in DC.
Is there a way to force an action to only process PDF files?
Edit:
Following #Joel Geraci's suggestion and finding this post, I've created the following script that runs in an action. At this point, It seems to run the profile, but I don't know if it actually modifies the document, since the call to this.closeDoc() doesn't prompt to save the document, and the resulting document doesn't seem to be saved as a PDF/A file.
/* Convert PDF/A-3a */
try
{
if(this.path.split('.').pop() === 'pdf')
{
var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");
if( oProfile != undefined )
{
var myPreflightResult = this.preflight( oProfile);
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
this.closeDoc();
}
}
}
catch(theError)
{
$error = theError;
this.closeDoc( {bNoSave : true} );
}
Edit 2:
I ended up settling on using the saveAs function. I'm not sure how to export the XML data to a file, but this seems to be sufficient.
/* Convert PDF/A-3a */
try
{
if(this.path.split('.').pop() === 'pdf')
{
var oThermometer = app.thermometer;
var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");
if( oProfile != undefined )
{
var myPreflightResult = this.preflight( oProfile, false, oThermometer );
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
if(myPreflightResult.numErrors > 0) {
var cXMLData = myPreflightResult.report(oThermometer);
console.println(cXMLData);
}
this.saveAs(path,"com.callas.preflight.pdfa");
}
}
}
catch(theError)
{
$error = theError;
this.closeDoc( {bNoSave : true} );
}
Edit 3:
So the problem is that non-PDF files are converted and read before my JavaScript is executed, which means that the this.path.split('.').pop() === 'pdf' doesn't actually filter out anything. I found that the requiresFullSave property of the Doc class specifies whether the document is a temp file or not. I have, however, found that I am still asked if I want to save the temp file, which doesn't help.
Edit 4
Calling Doc.closeDoc(true) on a temporary file causes Acrobat to crash and there doesn't seem to be another way to close a document without saving. I've found there is no clear way (that I've found) to close a temp document without prompting the user to save and have resorted to deleting all non-PDF files.
Final script:
/* Convert PDF/A-3a */
try
{
console.println(path + " is temp: " + requiresFullSave);
if(!requiresFullSave)
{
var oThermometer = app.thermometer;
var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");
if( oProfile != undefined )
{
var myPreflightResult = this.preflight( oProfile, false, oThermometer );
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
if(myPreflightResult.numErrors > 0) {
var cXMLData = myPreflightResult.report(oThermometer);
console.println(cXMLData);
}
this.saveAs(path,"com.callas.preflight.pdfa");
}
}
else{
// As noted in the documentation found [here][2]
// Note:If the document is temporary or newly created, setting dirty to false has no effect. That is, the user is still asked to save changes before closing the document. See requiresFullSave.
// this.dirty = false;
// this.closeDoc(true);
}
}
catch(theError)
{
}
Rather than creating an action that runs preflight, try creating an action that runs some JavaScript. The JavaScript would test for the file extension of the file being processed and then execute preflight via JavaScript if it's a PDF, skipping it if not.
I'm using wkhtmltopdf to convert pages to pdf but when I want to convert a secured page by user name and password but the site redirects the url to another page which requests the username and password although the user is already logged in.
The method which convert uses a processvar p = new System.Diagnostics.Process()
{
StartInfo =
{
FileName = pdfHtmlToPdfExePath,
Arguments = ((options == null) ? "" : String.Join(" ", options)) + " " + urlsSeparatedBySpaces + " " + outputFilename,
UseShellExecute = false, // needs to be false in order to redirect output
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = false, // redirect all 3, as it should be all 3 or none
WorkingDirectory = HttpContext.Current.Server.MapPath(outputFolder)
}
};
Anyone has any idea how to get out of this problem?
Regarding to the documentation (http://wkhtmltopdf.org/usage/wkhtmltopdf.txt) you should be able to pass cookies as arguments.
Try with code like the below before starting the external process, then the cookies you as user are sending to the server should be included with the request.
foreach(var cookie in System.Web.HttpContext.Current.Request.Cookies)
{
options += string.Format(" --cookie {0} {1}", cookie.Name, cookie.Value)
}
I have the following .js file being run using cscript on Windows Vista with Office 2007:
var err = 0;
var app = WScript.CreateObject("Word.Application");
try {
var filename = WScript.StdIn.ReadLine();
var enc = filename.toLowerCase().indexOf(".txt") >= 0 ? 65001 : 1252;
var objDoc = app.Documents.Open(filename, false, true, false, " ", " ", false, " ", " ", 0, enc, true, false, 0, true);
objDoc.PrintOut(false, false, 0, " ", " ", " ", 0);
} catch (e) {
err = 1;
} finally {
app.Quit(0);
}
WScript.Quit(err);
The point of the code is that it will accept a filename from stdin and print that document using Word. My problem is that for a particular printer we are testing with, the document doesn't get printed. I can trace that it executes .PrintOut properly and without any errors, and that the WINWORD process is started and terminated as expected (I can see it in the TaskManager). For our other test printer, the script works correctly.
I'm a bit new to this type of scripting (the guy who wrote it is on vacation...), any advice as to how I can resolve this problem?
Edit: I've isolated the PrintOut call, the rest of the script is irrelevant, even calling ActiveDocument.PrintOut from inside a Word document has the same problems with the printer.
Turns out the problem was the spaces in the strings in objDoc.PrintOut(false, false, 0, " ", " ", " ", 0); call. Removing the spaces fixed the problem.