diff --git a/cgi.d b/cgi.d index 9dcbf7e..da8ece5 100644 --- a/cgi.d +++ b/cgi.d @@ -40,9 +40,9 @@ You can also simulate a request by passing parameters on the command line, like: - ```console + $(CONSOLE ./yourprogram GET / name=adr - ``` + ) And it will print the result to stdout. diff --git a/http2.d b/http2.d index 8a111ab..3d05b2d 100644 --- a/http2.d +++ b/http2.d @@ -2,6 +2,9 @@ // Copyright 2013, Adam D. Ruppe. module arsd.http2; +// FIXME: multipart encoded file uploads needs implementation +// future: do web client api stuff + debug import std.stdio; import std.socket; @@ -77,25 +80,26 @@ string post(string url, string[string] args, string[string] cookies = null) { } +/ +/// struct HttpResponse { - int code; - string codeText; + int code; /// + string codeText; /// - string httpVersion; + string httpVersion; /// - string statusLine; + string statusLine; /// - string contentType; + string contentType; /// - string[string] cookies; + string[string] cookies; /// - string[] headers; - string[string] headersHash; + string[] headers; /// + string[string] headersHash; /// - ubyte[] content; - string contentText; + ubyte[] content; /// + string contentText; /// - HttpRequestParameters requestParameters; + HttpRequestParameters requestParameters; /// } import std.string; @@ -106,6 +110,7 @@ import std.range; // Copy pasta from cgi.d, then stripped down +/// struct Uri { alias toString this; // blargh idk a url really is a string, but should it be implicit? @@ -232,12 +237,13 @@ void main(string args[]) { } */ +/// struct BasicAuth { - string username; - string password; + string username; /// + string password; /// } -/* +/** When you send something, it creates a request and sends it asynchronously. The request object @@ -268,7 +274,6 @@ struct BasicAuth { request.waitForCompletion(); */ - class HttpRequest { private static { // we manage the actual connections. When a request is made on a particular @@ -696,7 +701,7 @@ class HttpRequest { // skip the tailing chunk of headers // FIXME if(data.length == 5 && data == [48, 13, 10, 13, 10]) - a = data.length; + a = cast(int) data.length; if(bodyReadingState.isGzipped || bodyReadingState.isDeflated) { auto n = uncompress.uncompress(responseData.content); @@ -741,6 +746,7 @@ class HttpRequest { this() { } + /// this(Uri where, HttpVerb method) { auto parts = where; requestParameters.method = method; @@ -870,42 +876,65 @@ class HttpRequest { // FIXME } - HttpRequestParameters requestParameters; + HttpRequestParameters requestParameters; /// } +/// struct HttpRequestParameters { // Duration timeout; // debugging - bool useHttp11 = true; - bool acceptGzip = true; + bool useHttp11 = true; /// + bool acceptGzip = true; /// // the request itself - HttpVerb method; - string host; - ushort port; - string uri; + HttpVerb method; /// + string host; /// + ushort port; /// + string uri; /// - bool ssl; + bool ssl; /// - string userAgent; - string authorization; + string userAgent; /// + string authorization; /// - string[string] cookies; + string[string] cookies; /// string[] headers; /// do not duplicate host, content-length, content-type, or any others that have a specific property - string contentType; - ubyte[] bodyData; + string contentType; /// + ubyte[] bodyData; /// } interface IHttpClient { } -enum HttpVerb { GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, PATCH, MERGE } +/// +enum HttpVerb { + /// + GET, + /// + HEAD, + /// + POST, + /// + PUT, + /// + DELETE, + /// + OPTIONS, + /// + TRACE, + /// + CONNECT, + /// + PATCH, + /// + MERGE +} -/* +/** Usage: auto client = new HttpClient("localhost", 80); @@ -920,12 +949,13 @@ enum HttpVerb { GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, PATCH, ME /// HttpClient keeps cookies, location, and some other state to reuse connections, when possible, like a web browser. class HttpClient { /* Protocol restrictions, useful to disable when debugging servers */ - bool useHttp11 = true; - bool acceptGzip = true; + bool useHttp11 = true; /// + bool acceptGzip = true; /// /// Automatically follow a redirection? - bool followLocation = false; + bool followLocation = false; /// + /// @property Uri location() { return currentUrl; } @@ -958,6 +988,7 @@ class HttpClient { // FIXME: add proxy // FIXME: some kind of caching + /// void setCookie(string name, string value, string domain = null) { if(domain == null) domain = currentDomain; @@ -965,6 +996,7 @@ class HttpClient { cookies[domain][name] = value; } + /// void clearCookies(string domain = null) { if(domain is null) cookies = null; @@ -973,8 +1005,8 @@ class HttpClient { } // If you set these, they will be pre-filled on all requests made with this client - string userAgent = "D arsd.html2"; - string authorization; + string userAgent = "D arsd.html2"; /// + string authorization; /// /* inter-request state */ string[string][string] cookies; @@ -998,14 +1030,15 @@ class SimpleCache : ICache { } } +/// struct HttpCookie { - string name; - string value; - string domain; - string path; - //SysTime expirationDate; - bool secure; - bool httpOnly; + string name; /// + string value; /// + string domain; /// + string path; /// + //SysTime expirationDate; /// + bool secure; /// + bool httpOnly; /// } // FIXME: websocket @@ -1102,7 +1135,7 @@ version(use_openssl) { override void connect(Address to) { super.connect(to); if(SSL_connect(ssl) == -1) { - ERR_print_errors_fp(stderr); + ERR_print_errors_fp(core.stdc.stdio.stderr); int i; printf("wtf\n"); scanf("%d\n", i); @@ -1114,7 +1147,7 @@ version(use_openssl) { override ptrdiff_t send(const(void)[] buf, SocketFlags flags) { auto retval = SSL_write(ssl, buf.ptr, cast(uint) buf.length); if(retval == -1) { - ERR_print_errors_fp(stderr); + ERR_print_errors_fp(core.stdc.stdio.stderr); int i; printf("wtf\n"); scanf("%d\n", i); @@ -1130,7 +1163,7 @@ version(use_openssl) { override ptrdiff_t receive(void[] buf, SocketFlags flags) { auto retval = SSL_read(ssl, buf.ptr, cast(int)buf.length); if(retval == -1) { - ERR_print_errors_fp(stderr); + ERR_print_errors_fp(core.stdc.stdio.stderr); int i; printf("wtf\n"); scanf("%d\n", i); diff --git a/simpledisplay.d b/simpledisplay.d index d70cf38..ec1b986 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -96,7 +96,7 @@ Examples: - $(DDOC_ANCHOR Event-example) + $(H3 Event-example) This program creates a window and draws events inside them as they happen, scrolling the text in the window as needed. Run this program and experiment to get a feel for where basic input events take place @@ -148,7 +148,7 @@ } --- - $(DDOC_ANCHOR Pong-example) + $(H3 Pong-example) This program creates a little Pong-like game. Player one is controlled with the keyboard. Player two is controlled with the mouse. It demos the pulse timer, event handling, and some basic drawing. @@ -278,8 +278,8 @@ $(H2 Topics) - $(H3 $(DDOC_ANCHOR topic-windows) Windows) - The $(LREF SimpleWindow) class is simpledisplay's flagship feature. It represents a single + $(H3 $(ID topic-windows) Windows) + The [SimpleWindow] class is simpledisplay's flagship feature. It represents a single window on the user's screen. You may create multiple windows, if the underlying platform supports it. You may check @@ -293,7 +293,7 @@ draw function title property - $(H3 $(DDOC_ANCHOR topic-event-loops) Event loops) + $(H3 $(ID topic-event-loops) Event loops) The simpledisplay event loop is designed to handle common cases easily while being extensible for more advanced cases, or replaceable by other libraries. The most common scenario is creating a window, then calling `window.eventLoop` when setup is complete. You can pass several handlers to the `eventLoop` method right there: @@ -317,14 +317,14 @@ It should be possible to integrate simpledisplay with vibe.d as well, though I haven't tried. - $(H3 $(DDOC_ANCHOR topic-notification-areas) Notification area (aka systray) icons) + $(H3 $(ID topic-notification-areas) Notification area (aka systray) icons) Notification area icons are currently only implemented on X11 targets. Windows support will come when I need it (or if someone requests it and I have some time to spend on it). - $(H3 $(DDOC_ANCHOR topic-input-handling) Input handling) + $(H3 $(ID topic-input-handling) Input handling) There are event handlers for low-level keyboard and mouse events, and higher level handlers for character events. - $(H3 $(DDOC_ANCHOR topic-2d-drawing) 2d Drawing) - To draw on your window, use the `window.draw` method. It returns a $(LREF ScreenPainter) structure with drawing methods. + $(H3 $(ID topic-2d-drawing) 2d Drawing) + To draw on your window, use the `window.draw` method. It returns a [ScreenPainter] structure with drawing methods. Important: `ScreenPainter` double-buffers and will not actually update the window until its destructor is run. Always ensure the painter instance goes out-of-scope before proceeding. You can do this by calling it inside an event handler, a timer callback, or an small scope inside main. For example: @@ -348,7 +348,7 @@ At this time, the 2d drawing does not support alpha blending. If you need that, use a 2d OpenGL context instead. FIXME add example of 2d opengl drawing here - $(H3 $(DDOC_ANCHOR topic-3d-drawing) 3d Drawing (or 2d with OpenGL)) + $(H3 $(ID topic-3d-drawing) 3d Drawing (or 2d with OpenGL)) simpledisplay can create OpenGL contexts on your window. It works quite differently than 2d drawing. Note that it is still possible to draw 2d on top of an OpenGL window, using the `draw` method, though I don't recommend it. @@ -372,7 +372,7 @@ } --- - $(H3 $(DDOC_ANCHOR topic-images) Displaying images) + $(H3 $(ID topic-images) Displaying images) You can also load PNG images using my `png.d`. --- @@ -390,16 +390,16 @@ If you find an image file which is a valid png that `arsd.png` fails to load, please let me know. In the mean time of fixing the bug, you can probably convert the file into an easier-to-load format. Be sure to turn OFF png interlacing, as that isn't supported. Other things to try would be making the image smaller, or trying 24 bit truecolor mode with an alpha channel. - $(H3 $(DDOC_ANCHOR topic-sprites) Sprites) - The $(LREF Sprite) class is used to make images on the display server for fast blitting to screen. This is especially important to use to support fast drawing of repeated images on a remote X11 link. + $(H3 $(ID topic-sprites) Sprites) + The [Sprite] class is used to make images on the display server for fast blitting to screen. This is especially important to use to support fast drawing of repeated images on a remote X11 link. - $(H3 $(DDOC_ANCHOR topic-clipboard) Clipboard) - The free functions $(LREF getClipboardText) and $(LREF setClipboardText) consist of simpledisplay's cross-platform clipboard support at this time. + $(H3 $(ID topic-clipboard) Clipboard) + The free functions [getClipboardText] and [setClipboardText] consist of simpledisplay's cross-platform clipboard support at this time. It also has helpers for handling X-specific events. - $(H3 $(DDOC_ANCHOR topic-timers) Timers) - There are two timers in simpledisplay: one is the pulse timeout you can set on the call to `window.eventLoop`, and the other is a customizable class, $(LREF Timer). + $(H3 $(ID topic-timers) Timers) + There are two timers in simpledisplay: one is the pulse timeout you can set on the call to `window.eventLoop`, and the other is a customizable class, [Timer]. The pulse timeout is used by setting a non-zero interval as the first argument to `eventLoop` function and adding a zero-argument delegate to handle the pulse. @@ -427,7 +427,7 @@ The `Timer` class works similarly, but is created separately from the event loop. (It still fires through the event loop, though.) You may make as many instances of `Timer` as you wish. - The pulse timer and instances of the $(LREF Timer) class may be combined at will. + The pulse timer and instances of the [Timer] class may be combined at will. --- import arsd.simpledisplay; @@ -445,20 +445,20 @@ Timers are currently only implemented on Windows, using `SetTimer` and Linux, using `timerfd_create`. These deliver timeout messages through your application event loop. - $(H3 $(DDOC_ANCHOR topic-os-helpers) OS-specific helpers) + $(H3 $(ID topic-os-helpers) OS-specific helpers) simpledisplay carries a lot of code to help implement itself without extra dependencies, and much of this code is available for you too, so you may extend the functionality yourself. See also: `xwindows.d` from my github. - $(H3 $(DDOC_ANCHOR topic-os-extension) Extending with OS-specific functionality) + $(H3 $(ID topic-os-extension) Extending with OS-specific functionality) `handleNativeEvent` and `handleNativeGlobalEvent`. - $(H3 $(DDOC_ANCHOR topic-integration) Integration with other libraries) + $(H3 $(ID topic-integration) Integration with other libraries) Integration with a third-party event loop is possible. On Linux, you might want to support both terminal input and GUI input. You can do this by using simpledisplay together with eventloop.d and terminal.d. - $(H3 $(DDOC_ANCHOR topic-guis) GUI widgets) + $(H3 $(ID topic-guis) GUI widgets) simpledisplay does not provide GUI widgets such as text areas, buttons, checkboxes, etc. It only gives basic windows, the ability to draw on it, receive input from it, and access native information for extension. You may write your own gui widgets with these, but you don't have to because I already did for you! Download `minigui.d` from my github repository and add it to your project. minigui builds these things on top of simpledisplay and offers its own Window class (and subclasses) to use that wrap SimpleWindow, adding a new event and drawing model that is hookable by subwidgets, represented by their own classes. @@ -467,7 +467,7 @@ minigui still needs a lot of work to be finished at this time, but it already offers a number of useful classes. - $(H2 $(DDOC_ANCHOR developer-notes) Developer notes) + $(H2 $(ID developer-notes) Developer notes) I don't have a Mac, so that code isn't maintained. I would like to have a Cocoa implementation though. @@ -499,8 +499,6 @@ declaration you're interested in, like `class SimpleWindow` using your editor's search function, then look at one piece at a time. - $(H2 $(DDOC_ANCHOR about-the-author) Meta) - Authors: Adam D. Ruppe with the help of others. If you need help, please email me with destructionator@gmail.com or find me on IRC. Our channel is #d on Freenode. I go by Destructionator or adam_d_ruppe, depending on which computer I'm logged into. @@ -514,17 +512,6 @@ building the documentation for simpledisplay yourself. It will give it a bit more style. Simply download the arsd.ddoc file and add it to your compile command when building docs. `dmd -c simpledisplay.d color.d -D arsd.ddoc` - -