| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 */ | 47 */ |
| 48 class HttpRequest { | 48 class HttpRequest { |
| 49 public: | 49 public: |
| 50 virtual ~HttpRequest() { } | 50 virtual ~HttpRequest() { } |
| 51 virtual const string& Path() = 0; | 51 virtual const string& Path() = 0; |
| 52 virtual const string& Referrer() = 0; | 52 virtual const string& Referrer() = 0; |
| 53 virtual const string& Host() = 0; | 53 virtual const string& Host() = 0; |
| 54 virtual const string& UserAgent() = 0; | 54 virtual const string& UserAgent() = 0; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 |
| 57 /** | 58 /** |
| 58 * The abstract superclass of http request processors. | 59 * The abstract superclass of http request processors. |
| 59 */ | 60 */ |
| 60 class HttpRequestProcessor { | 61 class HttpRequestProcessor { |
| 61 public: | 62 public: |
| 62 virtual ~HttpRequestProcessor() { } | 63 virtual ~HttpRequestProcessor() { } |
| 63 | 64 |
| 64 // Initialize this processor. The map contains options that control | 65 // Initialize this processor. The map contains options that control |
| 65 // how requests should be processed. | 66 // how requests should be processed. |
| 66 virtual bool Initialize(map<string, string>* options, | 67 virtual bool Initialize(map<string, string>* options, |
| 67 map<string, string>* output) = 0; | 68 map<string, string>* output) = 0; |
| 68 | 69 |
| 69 // Process a single request. | 70 // Process a single request. |
| 70 virtual bool Process(HttpRequest* req) = 0; | 71 virtual bool Process(HttpRequest* req) = 0; |
| 71 | 72 |
| 72 static void Log(const char* event); | 73 static void Log(const char* event); |
| 73 }; | 74 }; |
| 74 | 75 |
| 76 |
| 75 /** | 77 /** |
| 76 * An http request processor that is scriptable using JavaScript. | 78 * An http request processor that is scriptable using JavaScript. |
| 77 */ | 79 */ |
| 78 class JsHttpRequestProcessor : public HttpRequestProcessor { | 80 class JsHttpRequestProcessor : public HttpRequestProcessor { |
| 79 public: | 81 public: |
| 80 // Creates a new processor that processes requests by invoking the | 82 // Creates a new processor that processes requests by invoking the |
| 81 // Process function of the JavaScript script given as an argument. | 83 // Process function of the JavaScript script given as an argument. |
| 82 JsHttpRequestProcessor(Isolate* isolate, Handle<String> script) | 84 JsHttpRequestProcessor(Isolate* isolate, Handle<String> script) |
| 83 : isolate_(isolate), script_(script) { } | 85 : isolate_(isolate), script_(script) { } |
| 84 virtual ~JsHttpRequestProcessor(); | 86 virtual ~JsHttpRequestProcessor(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 Isolate* GetIsolate() { return isolate_; } | 130 Isolate* GetIsolate() { return isolate_; } |
| 129 | 131 |
| 130 Isolate* isolate_; | 132 Isolate* isolate_; |
| 131 Handle<String> script_; | 133 Handle<String> script_; |
| 132 Persistent<Context> context_; | 134 Persistent<Context> context_; |
| 133 Persistent<Function> process_; | 135 Persistent<Function> process_; |
| 134 static Persistent<ObjectTemplate> request_template_; | 136 static Persistent<ObjectTemplate> request_template_; |
| 135 static Persistent<ObjectTemplate> map_template_; | 137 static Persistent<ObjectTemplate> map_template_; |
| 136 }; | 138 }; |
| 137 | 139 |
| 140 |
| 138 // ------------------------- | 141 // ------------------------- |
| 139 // --- P r o c e s s o r --- | 142 // --- P r o c e s s o r --- |
| 140 // ------------------------- | 143 // ------------------------- |
| 141 | 144 |
| 142 | 145 |
| 143 static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 146 static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 144 if (args.Length() < 1) return; | 147 if (args.Length() < 1) return; |
| 145 HandleScope scope(args.GetIsolate()); | 148 HandleScope scope(args.GetIsolate()); |
| 146 Handle<Value> arg = args[0]; | 149 Handle<Value> arg = args[0]; |
| 147 String::Utf8Value value(arg); | 150 String::Utf8Value value(arg); |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 JsHttpRequestProcessor processor(isolate, source); | 644 JsHttpRequestProcessor processor(isolate, source); |
| 642 map<string, string> output; | 645 map<string, string> output; |
| 643 if (!processor.Initialize(&options, &output)) { | 646 if (!processor.Initialize(&options, &output)) { |
| 644 fprintf(stderr, "Error initializing processor.\n"); | 647 fprintf(stderr, "Error initializing processor.\n"); |
| 645 return 1; | 648 return 1; |
| 646 } | 649 } |
| 647 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) | 650 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) |
| 648 return 1; | 651 return 1; |
| 649 PrintMap(&output); | 652 PrintMap(&output); |
| 650 } | 653 } |
| OLD | NEW |