Permalink
Browse files

Added authentication and headers

  • Loading branch information...
1 parent 7df659a commit 8714e7c360200a3454545bafb9d03d199118b0d4 @mklepac mklepac committed Aug 26, 2015
Showing with 138 additions and 5 deletions.
  1. +1 −1 debug.css
  2. +66 −3 debug.js
  3. +71 −1 index.html
View
@@ -2,7 +2,7 @@ body {
padding-top: 60px;
}
-#allparameters {
+#allparameters, #allheaders, #authentication {
display: none;
}
View
@@ -1,3 +1,27 @@
+function showHeaders() {
+ showAuthHeaders();
+ showHeaderHeaders();
+ showParamHeaders();
+}
+
+function showAuthHeaders() {
+ if ($("#authentication").find(".realinputvalue").length > 0) {
+ $("#addauthbutton").hide();
+ $("#authentication").show();
+ } else {
+ $("#addauthbutton").show();
+ $("#authentication").hide();
+ }
+}
+
+function showHeaderHeaders() {
+ if ($("#allheaders").find(".realinputvalue").length > 0) {
+ $("#allheaders").show();
+ } else {
+ $("#allheaders").hide();
+ }
+}
+
function showParamHeaders() {
if ($("#allparameters").find(".realinputvalue").length > 0) {
$("#allparameters").show();
@@ -16,25 +40,44 @@ $(".fakeinputname").blur(function() {
$(".close").click(function(e) {
e.preventDefault();
$(this).parent().remove();
- showParamHeaders();
+ showHeaders();
+});
+
+$("#addauthbutton").click(function(e) {
+ e.preventDefault();
+ if ($("#authentication").find(".realinputvalue").length == 0) {
+ $('.httpauth:first').clone(true).appendTo("#authentication");
+ }
+ showHeaders();
+});
+
+$("#addheaderbutton").click(function(e) {
+ e.preventDefault();
+ $('.httpparameter:first').clone(true).appendTo("#allheaders");
+ showHeaders();
});
$("#addprambutton").click(function(e) {
e.preventDefault();
$('.httpparameter:first').clone(true).appendTo("#allparameters");
- showParamHeaders();
+ showHeaders();
});
$("#addfilebutton").click(function(e) {
e.preventDefault();
$('.httpfile:first').clone(true).appendTo("#allparameters");
- showParamHeaders();
+ showHeaders();
});
function postWithAjax(myajax) {
myajax = myajax || {};
myajax.url = $("#urlvalue").val();
myajax.type = $("#httpmethod").val();
+ if (checkForAuth())
+ {
+ myajax.username = $("#authentication input:first").val();
+ myajax.password = $("#authentication input").eq(1).val();
+ }
myajax.complete = function(jqXHR) {
$("#statuspre").text(
"HTTP " + jqXHR.status + " " + jqXHR.statusText);
@@ -75,13 +118,15 @@ $("#submitajax").click(function(e) {
e.preventDefault();
if(checkForFiles()){
postWithAjax({
+ headers: createHeaderData(),
data : createMultipart(),
cache: false,
contentType: false,
processData: false
});
} else {
postWithAjax({
+ headers : createHeaderData(),
data : createUrlData()
});
}
@@ -91,6 +136,10 @@ function checkForFiles() {
return $("#paramform").find(".input-file").length > 0;
}
+function checkForAuth() {
+ return $("#paramform").find("input[type=password]").length > 0;
+}
+
function createUrlData(){
var mydata = {};
var parameters = $("#allparameters").find(".realinputvalue");
@@ -125,6 +174,20 @@ function createMultipart(){
return(data)
}
+function createHeaderData(){
+ var mydata = {};
+ var parameters = $("#allheaders").find(".realinputvalue");
+ for (i = 0; i < parameters.length; i++) {
+ name = $(parameters).eq(i).attr("name");
+ if (name == undefined || name == "undefined") {
+ continue;
+ }
+ value = $(parameters).eq(i).val();
+ mydata[name] = value
+ }
+ return(mydata);
+}
+
function httpZeroError() {
$("#errordiv").append('<div class="alert alert-error"> <a class="close" data-dismiss="alert">&times;</a> <strong>Oh no!</strong> Javascript returned an HTTP 0 error. One common reason this might happen is that you requested a cross-domain resource from a server that did not include the appropriate CORS headers in the response. Better open up your Firebug...</div>');
}
View
@@ -53,13 +53,35 @@
<div class="span3">
<div class="control-group">
<div class="controls">
- <!-- <textarea class="input-xlarge realinputvalue" rows="2"></textarea>-->
<input type="text" class="input-xlarge realinputvalue" value="">
</div>
</div>
</div>
</div>
</div>
+
+ <div class="httpauth">
+ <a class="close">&times;</a>
+ <div class="row show-grid">
+ <div class="span2">
+ <div class="control-group">
+ <div class="controls">
+ <input type="text" class="input-medium fakeinputname" value="">
+ </div>
+ </div>
+ </div>
+
+ <div class="span3">
+ <div class="control-group">
+ <div class="controls">
+ <input type="password" class="input-xlarge realinputvalue" value="">
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
</div>
<div class="navbar navbar-fixed-top navbar-inverse">
@@ -123,6 +145,54 @@
<p class="help-block">Method and Endpoint are required. Click
below to add additional parameters.</p>
+ <div align="left">
+ <button id="addauthbutton" class="btn btn-primary" style="margin-bottom: 1.5em;">
+ <i class="icon-lock icon-white"></i> Add authentication
+ </button>
+ </div>
+
+ <div id="authentication">
+
+ <div class="row show-grid">
+ <div class="span2">
+ <div class="control-group">
+ <label class="control-label">Username</label>
+ </div>
+ </div>
+
+ <div class="span3">
+ <div class="control-group">
+ <label class="control-label">Password</label>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div id="allheaders">
+
+ <div class="row show-grid">
+ <div class="span2">
+ <div class="control-group">
+ <label class="control-label">Header Name</label>
+ </div>
+ </div>
+
+ <div class="span3">
+ <div class="control-group">
+ <label class="control-label">Header Value</label>
+ </div>
+ </div>
+ </div>
+
+ </div>
+
+ <div align="left">
+ <button id="addheaderbutton" class="btn btn-primary">
+ <i class="icon-plus icon-white"></i> Add header
+ </button>
+ </div>
+ <br />
+
<div id="allparameters">
<div class="row show-grid">

0 comments on commit 8714e7c

Please sign in to comment.