http is a unified Javascript RequireJS/CommonJS module for the browser or Wakanda Server (SSJS) which provides basic http constants and utilities.
- http.js - Fully commented script. Update to contribute.
- http.min.js - Minimized script. For normal use.
- http.no-md.js - Commented script without markdown comments. Use for debugging.
Standard and common custom HTTP header field names. See the module code for specific values.
Examples:
xhr.setRequestHeader(http.HEADER_FIELD_NAMES.CONTENT_TYPE, "text/plain");
The HTTP protocol status codes. See the module code for specific values.
Examples:
http.STATUS_CODES.OK; // 200
Determines if the status within xhr
indicates that an authentication error (401) occurred.
xhr
- An XMLHttpRequest object.
- Returns true if
xhr
indicates an authentication error and returns false otherwise.
Examples:
....
xhr.send();
if (http.isAuthErrorResponse(xhr)) {
// Reauthorize and try again.
}
Determines if the status within xhr
indicates that an error occurred.
xhr
- An XMLHttpRequest object.
- Returns true if
xhr
indicates an error and returns false otherwise.
Examples:
....
xhr.send();
if (http.isErrorResponse(xhr)) {
// Handle the error.
}
Converts the response headers in xhr
into a javascript object where the response fields become
the object's properties with their corresponding values.
xhr
- An XMLHttpRequest object.
- Returns the response headers within
xhr
as a javascript object.
Examples:
....
xhr.send();
headers = http.responseHeadersToObject(xhr);
// headers ==> {
// "Content-Length": 583727,
// "Content-Type": "text/html; charset=utf-8",
// "Last-Modified": "Tue, 15 Nov 1994 12:45:26 +0000"
// }
Returns a textual representation of the status within xhr
.
xhr
- An XMLHttpRequest object.
- See description.
Examples:
....
xhr.send();
http.statusText(xhr); // "200 OK"
If you contribute to this library, just modify http.js
and send a pull request. Please remember
to update the markdown if the public interface changes.
Licensed under MIT.
Copyright (C) 2013 Jeff Grann [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.