From dba281934a80df3744e5d71308b4a0de464d3633 Mon Sep 17 00:00:00 2001 From: mateo Date: Wed, 3 Jul 2024 19:59:13 -0700 Subject: [PATCH] misc changes --- .idea/.gitignore | 8 ++++++ .idea/modules.xml | 8 ++++++ .idea/tinyhttp.iml | 15 +++++++++++ .idea/vcs.xml | 7 +++++ profile.json | 1 + tinyhttp-internal/src/http.rs | 7 +---- tinyhttp-internal/src/lib.rs | 8 ++++-- tinyhttp-internal/src/response.rs | 43 ++++++++++++++++++++++++++++--- tinyhttp/src/lib.rs | 12 ++++++--- 9 files changed, 94 insertions(+), 15 deletions(-) create mode 100755 .idea/.gitignore create mode 100755 .idea/modules.xml create mode 100755 .idea/tinyhttp.iml create mode 100755 .idea/vcs.xml create mode 100755 profile.json diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100755 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100755 index 0000000..f5f14ff --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/tinyhttp.iml b/.idea/tinyhttp.iml new file mode 100755 index 0000000..adc7b2d --- /dev/null +++ b/.idea/tinyhttp.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100755 index 0000000..b78ce78 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/profile.json b/profile.json new file mode 100755 index 0000000..ea1a4f7 --- /dev/null +++ b/profile.json @@ -0,0 +1 @@ +{"meta":{"categories":[{"name":"Other","color":"grey","subcategories":["Other"]},{"name":"Regular","color":"blue","subcategories":["Other"]}],"debug":false,"extensions":{"baseURL":[],"id":[],"length":0,"name":[]},"interval":1.0,"preprocessedProfileVersion":44,"processType":0,"product":"example","sampleUnits":{"eventDelay":"ms","threadCPUDelta":"µs","time":"ms"},"startTime":1699554147361.684,"symbolicated":false,"pausedRanges":[],"version":24,"usesOnlyOneStackType":true,"doesNotUseFrameImplementation":true,"sourceCodeIsNotOnSearchfox":true,"markerSchema":[]},"libs":[{"name":"dyld","path":"/usr/lib/dyld","debugName":"dyld","debugPath":"/usr/lib/dyld","breakpadId":"EC7A3BA0F9BF3AB8A0F48622E5606B200","codeId":null,"arch":"arm64e"},{"name":"example","path":"/Users/mateo/Sync/RUST/tinyhttp/target/release/examples/example","debugName":"example","debugPath":"/Users/mateo/Sync/RUST/tinyhttp/target/release/examples/example","breakpadId":"E55FA13580E43DF393D62CB3A82B85810","codeId":null,"arch":"arm64"},{"name":"libsystem_kernel.dylib","path":"/usr/lib/system/libsystem_kernel.dylib","debugName":"libsystem_kernel.dylib","debugPath":"/usr/lib/system/libsystem_kernel.dylib","breakpadId":"B7751381144230B591B9AD7BE461BEBE0","codeId":null,"arch":"arm64e"},{"name":"libsystem_pthread.dylib","path":"/usr/lib/system/libsystem_pthread.dylib","debugName":"libsystem_pthread.dylib","debugPath":"/usr/lib/system/libsystem_pthread.dylib","breakpadId":"DAF953735DE639A1A6CED87F3F0629CC0","codeId":null,"arch":"arm64e"},{"name":"libdispatch.dylib","path":"/usr/lib/system/libdispatch.dylib","debugName":"libdispatch.dylib","debugPath":"/usr/lib/system/libdispatch.dylib","breakpadId":"DC1D018771493100BC63F633AFEBEE6C0","codeId":null,"arch":"arm64e"}],"threads":[{"frameTable":{"length":11,"address":[24799,23075,359095,16067,16043,21791,64659,373859,373519,393935,41472],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":11,"name":[1,3,4,5,6,7,8,9,10,11,13],"isJS":[false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,1,1,1,2],"fileName":[null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"GeckoMain","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":536.863791,"resourceTable":{"length":3,"lib":[0,1,2],"name":[0,2,12],"host":[null,null,null],"type":[1,1,1]},"samples":{"length":28,"stack":[10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10],"time":[537.095375,10837.75525,10838.850166,10969.47325,10970.476583,12165.493916,12166.654666,12338.706625,12339.705666,12501.778,12502.778875,12673.882333,12674.861625,12856.953,12857.968916,12993.000541,12994.026166,13192.307458,13193.334958,13321.405,13322.210958,13834.779916,13835.715666,18531.369916,18532.36825,19125.132416,19125.888458,19126.948833],"weight":[1,10271,1,121,1,1193,1,172,1,162,1,171,1,182,1,135,1,198,1,128,1,512,1,4677,1,592,1,1],"weightType":"samples","threadCPUDelta":[10404,0,102,0,68,0,93,0,87,0,66,0,79,0,79,0,68,0,37,0,30,0,49,0,53,0,53,0]},"stackTable":{"length":11,"prefix":[null,0,1,2,3,4,5,6,7,8,9],"frame":[0,1,2,3,4,5,6,7,8,9,10],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["dyld","0x60df","example","0x5a23","0x57ab7","0x3ec3","0x3eab","0x551f","0xfc93","0x5b463","0x5b30f","0x602cf","libsystem_kernel.dylib","0xa200"],"tid":578059,"unregisterTime":19127.936375},{"frameTable":{"length":23,"address":[28723,397407,253603,259335,59527,77475,374007,24128,259427,247603,230187,16087,6408,230095,227699,227727,227755,227783,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":23,"name":[1,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,24,25,26],"isJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,2,1,1,1,0,2,1,1,1,1,1,1,1,3,3,2],"fileName":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_1","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":10838.850166,"resourceTable":{"length":4,"lib":[3,1,2,4],"name":[0,2,9,23],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":17,"stack":[7,7,12,12,12,16,16,19,19,22,22,25,25,30,30,30,30],"time":[10838.850166,10839.764291,10840.969166,10841.745625,10842.927041,10844.14025,10852.933916,10857.031916,10866.132541,10867.196,10876.202583,10877.272791,10886.261666,10887.685458,13192.307458,13193.334958,19126.948833],"weight":[1,1,1,1,1,1,9,1,8,1,9,1,9,1,2297,1,5914],"weightType":"samples","threadCPUDelta":[110,0,233,0,5,48,0,13,0,7,0,6,0,29,0,97,0]},"stackTable":{"length":31,"prefix":[null,0,1,2,3,4,5,6,2,8,9,10,11,9,13,14,15,13,17,18,13,20,21,13,23,24,13,26,27,28,29],"frame":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,11,12,15,11,12,16,11,12,17,11,12,18,19,20,21,22],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f507","0xe887","0x12ea3","0x5b4f7","libsystem_kernel.dylib","0x5e40","0x3f563","0x3c733","0x3832b","0x3ed7","0x1908","0x382cf","0x37973","0x3798f","0x379ab","0x379c7","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","0x1830"],"tid":578256,"unregisterTime":19127.936375},{"frameTable":{"length":11,"address":[28723,397407,253603,259427,247603,230095,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":11,"name":[1,3,4,5,6,7,8,9,11,12,14],"isJS":[false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,1,2,2,3],"fileName":[null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_2","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":10970.476583,"resourceTable":{"length":4,"lib":[3,1,4,2],"name":[0,2,10,13],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":4,"stack":[10,10,10,10],"time":[10970.476583,13321.405,13322.210958,19126.948833],"weight":[1,2348,1,5785],"weightType":"samples","threadCPUDelta":[152,0,78,0]},"stackTable":{"length":11,"prefix":[null,0,1,2,3,4,5,6,7,8,9],"frame":[0,1,2,3,4,5,6,7,8,9,10],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","libsystem_kernel.dylib","0x1830"],"tid":578326,"unregisterTime":19127.936375},{"frameTable":{"length":11,"address":[28723,397407,253603,259427,247603,230095,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":11,"name":[1,3,4,5,6,7,8,9,11,12,14],"isJS":[false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,1,2,2,3],"fileName":[null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_3","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":12166.654666,"resourceTable":{"length":4,"lib":[3,1,4,2],"name":[0,2,10,13],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":4,"stack":[10,10,10,10],"time":[12166.654666,13834.779916,13835.715666,19126.948833],"weight":[1,1667,1,5272],"weightType":"samples","threadCPUDelta":[127,0,126,0]},"stackTable":{"length":11,"prefix":[null,0,1,2,3,4,5,6,7,8,9],"frame":[0,1,2,3,4,5,6,7,8,9,10],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","libsystem_kernel.dylib","0x1830"],"tid":578339,"unregisterTime":19127.936375},{"frameTable":{"length":16,"address":[28723,397407,253603,259427,247603,230095,227843,360819,17755,16043,6192,259495,59527,77475,374007,24128],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":16,"name":[1,3,4,5,6,7,8,9,11,12,14,15,16,17,18,19],"isJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,1,2,2,3,1,1,1,1,3],"fileName":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_4","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":12339.705666,"resourceTable":{"length":4,"lib":[3,1,4,2],"name":[0,2,10,13],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":5,"stack":[10,10,15,10,10],"time":[12339.705666,18531.369916,18532.36825,18533.351,19126.948833],"weight":[1,6172,1,1,593],"weightType":"samples","threadCPUDelta":[135,0,17,100,0]},"stackTable":{"length":16,"prefix":[null,0,1,2,3,4,5,6,7,8,9,2,11,12,13,14],"frame":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","libsystem_kernel.dylib","0x1830","0x3f5a7","0xe887","0x12ea3","0x5b4f7","0x5e40"],"tid":578340,"unregisterTime":19127.936375},{"frameTable":{"length":16,"address":[28723,397407,253603,259335,59527,77475,374007,24128,259427,247603,230095,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":16,"name":[1,3,4,5,6,7,8,10,11,12,13,14,15,17,18,19],"isJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,2,1,1,1,1,1,3,3,2],"fileName":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_5","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":12502.778875,"resourceTable":{"length":4,"lib":[3,1,2,4],"name":[0,2,9,16],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":3,"stack":[7,15,15],"time":[12502.778875,12503.757291,19126.948833],"weight":[1,1,6603],"weightType":"samples","threadCPUDelta":[32,98,0]},"stackTable":{"length":16,"prefix":[null,0,1,2,3,4,5,6,2,8,9,10,11,12,13,14],"frame":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f507","0xe887","0x12ea3","0x5b4f7","libsystem_kernel.dylib","0x5e40","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","0x1830"],"tid":578343,"unregisterTime":19127.936375},{"frameTable":{"length":16,"address":[28723,397407,253603,259335,59527,77475,374007,24128,259427,247603,230095,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":16,"name":[1,3,4,5,6,7,8,10,11,12,13,14,15,17,18,19],"isJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,2,1,1,1,1,1,3,3,2],"fileName":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_6","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":12674.861625,"resourceTable":{"length":4,"lib":[3,1,2,4],"name":[0,2,9,16],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":3,"stack":[7,15,15],"time":[12674.861625,12675.695625,19126.948833],"weight":[1,1,6431],"weightType":"samples","threadCPUDelta":[28,127,0]},"stackTable":{"length":16,"prefix":[null,0,1,2,3,4,5,6,2,8,9,10,11,12,13,14],"frame":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f507","0xe887","0x12ea3","0x5b4f7","libsystem_kernel.dylib","0x5e40","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","0x1830"],"tid":578344,"unregisterTime":19127.936375},{"frameTable":{"length":11,"address":[28723,397407,253603,259427,247603,230095,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":11,"name":[1,3,4,5,6,7,8,9,11,12,14],"isJS":[false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,1,2,2,3],"fileName":[null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_7","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":12857.968916,"resourceTable":{"length":4,"lib":[3,1,4,2],"name":[0,2,10,13],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":2,"stack":[10,10],"time":[12857.968916,19126.948833],"weight":[1,6249],"weightType":"samples","threadCPUDelta":[135,0]},"stackTable":{"length":11,"prefix":[null,0,1,2,3,4,5,6,7,8,9],"frame":[0,1,2,3,4,5,6,7,8,9,10],"category":[1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","libsystem_kernel.dylib","0x1830"],"tid":578345,"unregisterTime":19127.936375},{"frameTable":{"length":16,"address":[28723,397407,253603,259335,59527,77475,374007,24128,259427,247603,230095,227843,360819,17755,16043,6192],"inlineDepth":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"func":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"nativeSymbol":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"innerWindowID":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"implementation":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"line":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"column":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"optimizations":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"funcTable":{"length":16,"name":[1,3,4,5,6,7,8,10,11,12,13,14,15,17,18,19],"isJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"relevantForJS":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],"resource":[0,1,1,1,1,1,1,2,1,1,1,1,1,3,3,2],"fileName":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"lineNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"columnNumber":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"markers":{"length":0,"category":[],"data":[],"endTime":[],"name":[],"phase":[],"startTime":[]},"name":"rusty_pool_1_thread_8","nativeSymbols":{"length":0,"address":[],"functionSize":[],"libIndex":[],"name":[]},"pausedRanges":[],"pid":44514,"processName":"example","processShutdownTime":19127.936375,"processStartupTime":536.863791,"processType":"default","registerTime":12994.026166,"resourceTable":{"length":4,"lib":[3,1,2,4],"name":[0,2,9,16],"host":[null,null,null,null],"type":[1,1,1,1]},"samples":{"length":3,"stack":[7,15,15],"time":[12994.026166,12995.007583,19126.948833],"weight":[1,1,6112],"weightType":"samples","threadCPUDelta":[29,110,0]},"stackTable":{"length":16,"prefix":[null,0,1,2,3,4,5,6,2,8,9,10,11,12,13,14],"frame":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"category":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"subcategory":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"stringArray":["libsystem_pthread.dylib","0x7033","example","0x6105f","0x3dea3","0x3f507","0xe887","0x12ea3","0x5b4f7","libsystem_kernel.dylib","0x5e40","0x3f563","0x3c733","0x382cf","0x37a03","0x58173","libdispatch.dylib","0x455b","0x3eab","0x1830"],"tid":578346,"unregisterTime":19127.936375}],"pages":[],"profilerOverhead":[],"counters":[]} \ No newline at end of file diff --git a/tinyhttp-internal/src/http.rs b/tinyhttp-internal/src/http.rs index 923dd87..14852e1 100755 --- a/tinyhttp-internal/src/http.rs +++ b/tinyhttp-internal/src/http.rs @@ -123,12 +123,7 @@ fn build_and_parse_req(conn: &mut P) -> Result { .parse::() .unwrap(); - let mut raw_body = Vec::with_capacity(body_len); - - // Zero-init raw_body - (0..body_len).for_each(|_| { - raw_body.push(0); - }); + let mut raw_body = vec![0; body_len]; buf_reader.read_exact(&mut raw_body).unwrap(); diff --git a/tinyhttp-internal/src/lib.rs b/tinyhttp-internal/src/lib.rs index 2e8a744..f3ef0f1 100755 --- a/tinyhttp-internal/src/lib.rs +++ b/tinyhttp-internal/src/lib.rs @@ -14,13 +14,17 @@ pub mod async_http; #[cfg(test)] mod tests { + use std::collections::HashMap; #[test] fn build_request() { use crate::request::Request; + let mut headers = HashMap::new(); + headers.insert("content-type".to_string(), "text/plain".to_string()); + let request = Request::new( - b"Hello, World!", - vec!["Content-Type: text/plain".to_string()], + b"Hello, World!".to_vec(), + headers, vec![ "GET".to_string(), "/test".to_string(), diff --git a/tinyhttp-internal/src/response.rs b/tinyhttp-internal/src/response.rs index 0274245..db4cd38 100755 --- a/tinyhttp-internal/src/response.rs +++ b/tinyhttp-internal/src/response.rs @@ -1,5 +1,6 @@ use std::{ collections::HashMap, + error::Error, io::{Read, Write}, }; @@ -23,19 +24,55 @@ impl Default for Response { impl<'a> From<&'a str> for Response { fn from(value: &'a str) -> Self { - Response::new().body(value.into()).mime("text/plain").status_line("HTTP/1.1 200 OK") + Response::new() + .body(value.into()) + .mime("text/plain") + .status_line("HTTP/1.1 200 OK") } } impl From for Response { fn from(value: String) -> Self { - Response::new().body(value.into_bytes()).mime("text/plain").status_line("HTTP/1.1 200 OK") + Response::new() + .body(value.into_bytes()) + .mime("text/plain") + .status_line("HTTP/1.1 200 OK") } } impl From> for Response { fn from(value: Vec) -> Self { - Response::new().body(value).mime("application/octet-stream").status_line("HTTP/1.1 200 OK") + Response::new() + .body(value) + .mime("application/octet-stream") + .status_line("HTTP/1.1 200 OK") + } +} + +impl From<()> for Response { + fn from(_value: ()) -> Self { + Response::new() + .body(vec![]) + .mime("text/plain") + .status_line("HTTP/1.1 403 Forbidden") + } +} + +impl, E: Error + Into> From> for Response { + fn from(value: Result) -> Self { + match value { + Ok(body) => body.into(), + Err(e) => e.into(), + } + } +} + +impl From> for Response { + fn from(value: Box) -> Self { + Response::new() + .body(value.to_string().into_bytes()) + .mime("text/plain") + .status_line("HTTP/1.1 403 Forbidden") } } diff --git a/tinyhttp/src/lib.rs b/tinyhttp/src/lib.rs index ffd590e..f370df2 100755 --- a/tinyhttp/src/lib.rs +++ b/tinyhttp/src/lib.rs @@ -95,7 +95,7 @@ pub mod prelude { #[cfg(test)] mod tests { - use std::{sync::OnceLock, thread, time::Duration}; + use std::{collections::HashMap, sync::OnceLock, thread, time::Duration}; static HTTP_ENABLED: OnceLock = OnceLock::new(); @@ -189,7 +189,7 @@ mod tests { let headers = body.get_headers(); format!( "Accept-Encoding: {}", - headers.get("Accept-Encoding").unwrap() + headers.get("accept-encoding").unwrap() ) } @@ -202,9 +202,13 @@ mod tests { .unwrap() .wildcard() .is_none()); + + let mut headers = HashMap::new(); + headers.insert("accept-encoding".to_string(), "gzip".to_string()); + let request = Request::new( - b"Hello", - vec!["Accept-Encoding: gzip".to_string()], + b"Hello".to_vec(), + headers, vec!["GET".to_string(), "/".to_string(), "HTTP/1.1".to_string()], None, );